问题
I want to run an R-script from the command line (on a Linux machine) and store the results in a subdirectory of the working directory. It looks like that:
./myscript.r [param 1] [param 2] [param 3]
Given 3 binomial parameters there are 4 conditions in total. I want to store the results of each condition in a subdirectory of the working directory.
Is there an elegant way to do that or do I really need to copy my R-script to every subdirectory?
回答1:
Purcell,try saving and running this script on your computer. Provide it a few different kinds and combinations of arguments.
#!/usr/bin/Rscript
args <- commandArgs(TRUE)
print(args)
class(args)
For instance, I ran ./test.R test=1 one=test
.
Using this command in combination with paste0()
statements should give you what you need to tailor your output locations based on the parameters provided.
来源:https://stackoverflow.com/questions/29928633/run-an-r-script-from-command-line-and-store-results-in-subdirectory