719016
719016

Reputation: 10431

R pass an Rscript command line with parameters to emacs ESS?

I would like to be able to debug an R script that is called with a list of parameters via emacs ESS. For example:

/specific/version/of/R/bin/Rscript \
    /my/dir/script.R \
    firstparam \
    /second/param/is/a/file.txt

Instead of my ESS session just calling R with no parameters, how can I pass these parameters above to the ESS session and debug the script line by line?

Upvotes: 0

Views: 152

Answers (1)

Gavin Kelly
Gavin Kelly

Reputation: 2414

I imagine script.R probably invokes the commandArgs functionality. I don't think there's a way to 'write' to this once you've invoked R within , but once your script is open in emacs, and you have invoked R in the usual way, then step through the script as usual, but prior to any lines resembling myvar <- commandArgs()[2], manually set myvar (or whatever variable the script is setting!) to firstparam, rather than allowing the commandArgs to attempt to read from the original command line.

Alternatively, you can invoke R to prompt you for optional arguments to R by using C-u M-x R and manually typing in firstparam etc, but the index of the arguments might not sync nicely between Rscript and your ESS's way of calling R, so experimentation may be needed.

Upvotes: 1

Related Questions