r - Changing directories in Rscript -
r - Changing directories in Rscript -
how can have rscript parameters alter directories?
if command-line argument rscript test.r "foo1", want setwd("~/foo1")
, error cannot alter working directory.
args<-commandargs(trailingonly=true) lambda<args[1] fileend<-args[2] replicate<-args[3] directory<-args[4] setwd(directory)
a sample command-line rscript test.r 0 1 10 "~/foo1"
try this:
# utilize commandline arguments args <- commandargs(true) # first argument working dir working.dir <- args[1] # alter working dir setwd(file.path("~", working.dir))
r command-line-arguments directory rscript
Comments
Post a Comment