Dear R experts This probably seems very easy to you guys, but I'm a beginner and would be really glad if someone helped me with this: I am trying to automate the execution of an R script (let's call it "myscript.R") by passing a variable from a bash script to myscript.R. I know I can use the command Rscript, but I don't know how to declare in bash which variable will be accessed by the "commandArgs" command in myscript.R.
So my bash script looks about like this: #!/bin/bash VARIABLES=( a b c d ) for i in ${VARIABLES[@]}; do VARIABLENAME=$i Rscript -e 'source("myscript.R")' done In myscript.R, I would like to use the current VARIABLENAME when executing the program, i.e., myscript <- function() { args <- commandArgs(TRUE) # args should now be set to either a,b,c, or d load(paste("/home/user/../../", args, ".RData", sep="")) # this defines the path to the data file that will be used in this run ...further commands... } At the moment, myscript.R doesn't seem to be executed at all when I execute the bash script. Any help will be greatly appreciated! Thanks, sophie -- View this message in context: http://r.789695.n4.nabble.com/export-variable-from-bash-to-R-tp4647749.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.