Skip to content

Consider storing background-process R commands in files #781

@ElianHugh

Description

@ElianHugh

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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    engineeringMaintenance, style, development process

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions