Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide R package-related tasks #59

Open
jacob-long opened this issue Apr 3, 2018 · 14 comments
Open

Provide R package-related tasks #59

jacob-long opened this issue Apr 3, 2018 · 14 comments

Comments

@jacob-long
Copy link
Contributor

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.

@Ikuyadeu Ikuyadeu self-assigned this Apr 4, 2018
@Ikuyadeu
Copy link
Member

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

@andycraig
Copy link
Collaborator

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

@jacob-long
Copy link
Contributor Author

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

@andycraig
Copy link
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!

@crsh
Copy link

crsh commented Jun 28, 2020

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
            }
        }
    ]
}

@maxheld83
Copy link

maxheld83 commented Feb 9, 2021

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"
            ]
        }
    ]
}

@andycraig
Copy link
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!

@jolars
Copy link
Contributor

jolars commented Feb 26, 2021

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?

@maxheld83

This comment has been minimized.

@krlmlr
Copy link
Contributor

krlmlr commented Mar 17, 2021

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

@andycraig
Copy link
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

@krlmlr
Copy link
Contributor

krlmlr commented Apr 5, 2021

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

@andycraig
Copy link
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

@krlmlr krlmlr mentioned this issue Apr 6, 2021
@gowerc
Copy link
Contributor

gowerc commented Feb 16, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants