Skip to content

Provide R package-related tasks #59

Description

@jacob-long

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.

Activity

  1. self-assigned this
    on Apr 4, 2018
  2. Ikuyadeu commented on Apr 15, 2018

    @Ikuyadeu
    Member

    @jacob-long Sorry my late reply.
    Good idea! if you have a task JSON files, could you share it?

  3. andycraig commented on Nov 25, 2019

    @andycraig
    Collaborator

    Hi @jacob-long, I’m following up on some old issues. Are tasks still something you’re keen to see added?

  4. jacob-long commented on Nov 27, 2019

    @jacob-long
    ContributorAuthor

    I think these would be valuable additions to support R package developer workflows.

  5. andycraig commented on Nov 27, 2019

    @andycraig
    Collaborator

    @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() and devtools::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!

  6. crsh commented on Jun 28, 2020

    @crsh

    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
                }
            }
        ]
    }
  7. maxheld83 commented on Feb 9, 2021

    @maxheld83

    based 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: Document shortcuts 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 for devtools::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"
                ]
            }
        ]
    }
    
  8. andycraig commented on Feb 11, 2021

    @andycraig
    Collaborator

    @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!

  9. jolars commented on Feb 26, 2021

    @jolars
    Contributor

    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?

  10. maxheld83 commented on Feb 26, 2021

    @maxheld83
  11. krlmlr commented on Mar 17, 2021

    @krlmlr
    Contributor

    @jolars: I have mapped workbench.action.terminal.relaunch to Ctrl + Shift + F10 to restart the active terminal if the active language is R. Works for me.

  12. andycraig commented on Apr 4, 2021

    @andycraig
    Collaborator

    I'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-L154

  13. krlmlr commented on Apr 5, 2021

    @krlmlr
    Contributor

    Nice! I wonder if we can use "problemMatchers" to implement tasks that work on the active document, e.g. "knit".

  14. andycraig commented on Apr 5, 2021

    @andycraig
    Collaborator

    @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

  15. gowerc commented on Feb 16, 2022

    @gowerc
    Contributor

    This is quite a meaty issue now I'm wondering if its worth splitting it into sub issues namely:

  16. ThomasSoeiro commented on Sep 26, 2026

    @ThomasSoeiro
    Collaborator

    #1474 (now closed) specifically asked support for devtools::test_active_file()

  17. ThomasSoeiro commented on Sep 27, 2026

    @ThomasSoeiro
    Collaborator

    @eitsupi @Fred-Wu @grantmcdermott Perhaps it can be converted to discussion?

  18. locked and limited conversation to collaborators on Sep 27, 2026
  19. converted this issue into a discussion #1789 on Sep 27, 2026
  20. marked Improve Task documentation #1003 as a duplicate of this issue on Sep 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions