Run an R-script from command line and store results in subdirectory

江枫思渺然 提交于 2020-01-04 13:58:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!