Repository navigation
Provide R package-related tasks #59
Description
Activity
@jacob-long Sorry my late reply.
Good idea! if you have a task JSON files, could you share it?Hi @jacob-long, I’m following up on some old issues. Are tasks still something you’re keen to see added?
I think these would be valuable additions to support R package developer workflows.
@jacob-long Great! It sounds like you might already have some task definition JSON files that you can share? If so, that would be very useful.
I structure most of my projects as packages and use a workflow based around
devtools::load_all()anddevtools::test(), but I’ve never submitted a package to CRAN, used R CMD, or used VSCode tasks. Would you be able to provide a list of desired tasks and what they should do? I’m happy to help out on the implementation side of things.Thank you!
Sorry, to barge in. I'm only just getting started using VS Code, but in case it helps, my set up looks as follows:
{ "version": "2.0.0", "tasks": [ { "label": "Build package", "type": "shell", "command": "RScript -e 'devtools::install(upgrade = \"never\")'", "presentation": { "reveal": "always" }, "problemMatcher": [], "group": { "kind": "build", "isDefault": true } }, { "label": "Run unit tests", "type": "shell", "command": "RScript -e 'devtools::test()'", "presentation": { "reveal": "always" }, "problemMatcher": [], "group": { "kind": "test", "isDefault": true } }, { "label": "Run R CMD checks", "type": "shell", "command": "RScript -e 'devtools::check()'", "presentation": { "reveal": "always" }, "problemMatcher": [], "group": { "kind": "test", "isDefault": false } } ] }Reacted by amarin and Yun Pengbased on @crsh's example, I've factored out/expanded this a bit to replicate as much as possible the RStudio build pane.
(Corresponding keymaps are in #551).I understand there's a way to make an extension a proper Task provider.
I think this might also warrant deprecating the
R: Documentshortcuts in the command picker now, since a task is arguably the proper way to do this.
In particular, the tasks run in their own R session, which makes sense fordevtools::document().I'm not knowledgeable about TypeScript (?), let alone VSCode extensions, otherwise I'd be happy to make PR, but I can help curate the tasks (rmarkdown, shiny, etc).
Here's what I got:
{ "version": "2.0.0", "options": { "shell": { "executable": "Rscript", "args": [ "-e" ] } }, "presentation": { "reveal": "always", "panel": "shared", "showReuseMessage": false, "group": "build" }, "type": "shell", "problemMatcher": [], "tasks": [ { "label": "Document", "command": "devtools::document(roclets = c('rd', 'collate', 'namespace'))", "problemMatcher": [] }, { "label": "Install", "command": "devtools::install(quick = TRUE, upgrade = 'never')", "group": "build", "dependsOn": "Document" }, { "label": "Test", "command": "devtools::test()", "group": "test", "problemMatcher": [] }, { "label": "Check", "command": "devtools::check(error_on = 'warning')", "group": { "kind": "test", "isDefault": true }, "dependsOn": "Document" }, { "label": "Pkgdown", "command": "muggle::build_site2()", "group": { "kind": "build", "isDefault": true }, "dependsOn": "Document", "problemMatcher": [] }, { "label": "Build and Test", "dependsOn": [ "Pkgdown", "Check" ] } ] }@crsh Thank you for posting that info, and apologies for not responding! I completely missed the notification.
@maxheld83 Thank you for the followup on this issue. This isn't something I'm going to pursue any time soon, but contributions are very welcome!
Good idea, and thanks for the task configs. To really emulate the functionality from R Studio, it would be nice if it was possible to restart the R Session (and run
library(<package>), just like the Install and Restart function does in R Studio.I've fiddled a bit with the tasks, but I'm not sure how to do this properly. It's of course easy to start up R as part of the task, but then the R extension does not recognize the new console as the "main" R terminal, and sends commands to either a new terminal or the old one (if it was already opened).
What I'd like to achieve is to have the task reuse the standard R terminal. Does anyone know how to achieve this?
@jolars: I have mapped
workbench.action.terminal.relaunchto Ctrl + Shift + F10 to restart the active terminal if the active language is R. Works for me.Reacted by Johan LarssonI've added tasks for Check, Document, Install and Test.
It should be fairly easy to add new tasks by copy-pasting the code for these tasks, which is here:
https://github.com/Ikuyadeu/vscode-R/blob/17a7d69423d3a4377211e83f39ebc3bceba6ab69/src/extension.ts#L147-L154Nice! I wonder if we can use "problemMatchers" to implement tasks that work on the active document, e.g. "knit".
@krlmlr I think problem matchers work on the output of tasks. For tasks that use the active file, we might be able to use variable substitution: https://code.visualstudio.com/docs/editor/variables-reference
This is quite a meaty issue now I'm wondering if its worth splitting it into sub issues namely:
- Add knitr task (Further possible requirements listed in Add knit task #608)
- Add problemMatchers (already partially implemented in WIP: Add problemMatching to task #989 but probably needs to be refined)
- Enhance existing tasks (currently we have the most basic implementation
devtools::document()it might be worth updating them in line with Provide R package-related tasks #59 (comment))
#1474 (now closed) specifically asked support for
devtools::test_active_file()@eitsupi @Fred-Wu @grantmcdermott Perhaps it can be converted to discussion?
Reacted by eitsupi- locked and limited conversation to collaborators
on Sep 27, 2026
There are some things added in one of the recent releases that we should consider including as VS Code tasks as well.
In particular, being able to run tests and R CMD check is ideally-suited to tasks.
I wasn't sure whether an extension can provide tasks in this way, but it appears to be possible. I don't know TypeScript well enough to implement, but here's an example of an extension that provides users with tasks: https://github.com/Microsoft/vscode-extension-samples/tree/master/task-provider-sample
I can help in terms of putting together the task definition JSONs since I'm using some in my own projects already.