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

Consider storing background-process R commands in files #781

Closed
ElianHugh opened this issue Sep 9, 2021 · 1 comment · Fixed by #783
Closed

Consider storing background-process R commands in files #781

ElianHugh opened this issue Sep 9, 2021 · 1 comment · Fixed by #783
Labels
engineering Maintenance, style, development process

Comments

@ElianHugh
Copy link
Collaborator

Many of VSCode-R's features use a background R process to perform tasks (e.g., help providers, previewing and knitting documents). We currently define the calls to R in-line, e.g.

      const cmd = (
            `knitr::opts_knit[['set']](root.dir = ${knitWorkingDirText});` +
            `cat('${lim}', rmarkdown::render(` +
            `'${filePath.replace(/\\/g, '/')}',` +
            `output_format = rmarkdown::html_document(),` +
            `output_file = '${outputFile.replace(/\\/g, '/')}',` +
            `intermediates_dir = '${tmpDir().replace(/\\/g, '/')}'), '${lim}',` +
            `sep='')`
        );

I think that long-term this could get hard to maintain. Also, it can be difficult to wrap your head around all the quoting!

Describe the solution you'd like

I think that it might be neater and easier to maintain if we instead stuck these calls in their own R files, and then sourced them. For instance:

cp.spawn(`R -f test.R`) 

We can use the commandArgs method to pass values to a given file. E.g.

# test.r
print(commandArgs(trailingOnly = TRUE))
R --silent --slave --no-save -f test.r --args "arg1" "arg2" "arg3"
#> [1] "arg1" "arg2" "arg3"
@ElianHugh ElianHugh added the engineering Maintenance, style, development process label Sep 9, 2021
@renkun-ken
Copy link
Member

That's true. If we want more simplicity and don't need to show up the arguments in the command line, we could even use environment variables to pass arguments into the scripts.

ElianHugh added a commit that referenced this issue Sep 10, 2021
Fixes regression with #781 due to a typo in requireNamespace
ElianHugh added a commit to ElianHugh/vscode-R that referenced this issue May 12, 2022
Fixes regression with REditorSupport#781 due to a typo in requireNamespace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
engineering Maintenance, style, development process
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants