我正在使用命令行(Linux)使用 rscript 运行R脚本:
Rscript myscript.R inputfile1.csv inputfile.csv integerArg
我的命令args构造了这样的
cmd_args <- commandArgs()
infile1 <- cmd_args[1]
infile2 <- cmd_args[2]
intArg <- cmd_args[3]
main_func<-function(infile1, infile2, intArg){
print(infile1)
print(infile2)
print(intArg)
}
main_func(infile1, infile2, intArg)
构造
[1]
[1]“ - 奴隶”
[1]“ - 没有返回”
我想我不必告诉您,脚本第一次击中输入参数之一时,该脚本会出现错误。
我还尝试过这样运行脚本,并且它给出了完全相同的输出/错误
r - l-slave -no-restore -file = myScript.r -args inputfile1.csv inputfile.csv integerarg
我很困惑,因为我在调用rscript时没有设置这些标志,所以它们为什么出现,如何使Commandargs仅读取指定的输入参数?关于如何解决此问题的任何想法?我似乎找不到有关为什么会发生这种情况的任何信息,显然我只是缺少一些东西。非常感谢。
I am running an R script using Rscript from the command line (linux) like this:
Rscript myscript.R inputfile1.csv inputfile.csv integerArg
My command args are structured like this
cmd_args <- commandArgs()
infile1 <- cmd_args[1]
infile2 <- cmd_args[2]
intArg <- cmd_args[3]
main_func<-function(infile1, infile2, intArg){
print(infile1)
print(infile2)
print(intArg)
}
main_func(infile1, infile2, intArg)
This prints out
[1] "/home/miniconda3/envs/bionano_python3.0/lib/R/bin/exec/R"
[1] "--slave"
[1] "--no-restore"
I guess I don't have to tell you that the script gives an error the first time it hits one of the input arguments.
I have also tried running the script like this and it gives the exact same output/error
R --slave --no-restore --file=myscript.R --args inputfile1.csv inputfile.csv integerArg
I'm confused because I am not setting these flags when I call Rscript so why are they appearing, and how can I make the commandArgs read only the designated input parameters? Any ideas on how to solve this issue? I can't seem to find any information about why this could be happening and I'm clearly just missing something. Thanks so much in advance.
发布评论
评论(1)
rscript
“就是这样”。一个修复程序:使用
commandargs(trielingonly = true)
另一个修复程序:使用
littler
(请参阅 littler at cran ,将类似于trialingonly = trile = true
true 的参数介绍,然后将它们留在`argv [] []和另一个修复程序中:使用eg
docOptt
标准化选项过程(请参阅 docopt at cran。在
nofollow noreferrer“> Inst/示例中的littler repo 。我每天多年都使用了许多这些。正如他们所说,“为我工作”。
littler
docopt"That's just the way it is" with
Rscript
.One fix: use
commandArgs(trailingOnly=TRUE)
Another fix: use
littler
(see littler at CRAN which prunes the arguments similar totrailingOnly=TRUE
and leaves them in `argv[]And another fix: use eg
docopt
which standardizes option process (see docopt at CRAN.There are a bunch of examples combining
littler
anddocopt
in the littler repo in inst/examples. I have used a number of those daily for many years. "Works for me" as they say.