简体   繁体   English

R中的命令行参数

[英]Command Line arguments in R

I'd like to know if it's possible to pass a string as a command line argument to execute in R? 我想知道是否可以通过字符串作为命令行参数在R中执行?

I've attempted it already and I think it's parsing based on space, regardless of quotation marks. 我已经尝试过了,并且我认为它是基于空格的,而不考虑引号。

./R_Script.r abc.bed def.bed "cat bedgraph 1,2"

It shouldn't be parsing based on space. 它不应该基于空间进行解析。 I'm also not sure why you are trying to execute your R script file directly, rather than using Rscript and passing the script file. 我也不确定为什么您要尝试直接执行R脚本文件,而不是使用Rscript并传递脚本文件。 If your R_Script.r file contains only one line: commandArgs() , then running this line: 如果您的R_Script.r文件仅包含一行: commandArgs() ,则运行此行:

Rscript --vanilla R_Script.r "first second"

should get you: 应该给你:

[1] "/usr/local/lib/R/bin/exec/R" "--slave"
[3] "--no-restore"                "--vanilla"
[5] "--file=R_Script.r"           "--args"
[7] "first second"

As you can see, the 7th element of the list is first second , so it isn't parsing the space. 如您所见,列表的第7个元素是first second ,因此它没有解析空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM