I want to use RStudio to edit an R-script having command line parameters, e.g.,
my_rscript --dataset mydataset
and then to read the optiion
This is really old but I stumbled across it when trying to do the same thing and I've ended up just trying the following, and is nice and quick if people want to try it (probably only useful for commands that have a couple of easy args though):
Given my Rscript which currently starts:
args <- commandArgs(TRUE)
df <- read.csv(args[1], sep=",", check.names=FALSE, row.names = 1)
.
. # Do some analysis and plotting etc.
.
If I wanted to emulate the command line that the Rscript would otherwise receive, you can make the args
vector up 'manually':
args <- c("/path/to/my/inputfile.csv")
then args[1]
takes on the same value it always would have. and I simply run everything else in the script by highlighting and executing in RStudio.