为什么是“奴隶” &&quot-无房子”当我用rscript调用我的r文件时,命令使用

发布于 2025-01-28 16:53:47 字数 833 浏览 2 评论 0 原文

我正在使用命令行(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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遮了一弯 2025-02-04 16:53:47

rscript “就是这样”。

一个修复程序:使用 commandargs(trielingonly = true)

另一个修复程序:使用 littler (请参阅 littler at cran ,将类似于 trialingonly = trile = true true 的参数介绍,然后将它们留在`argv [] []

和另一个修复程序中:使用eg docOptt 标准化选项过程(请参阅 docopt at cran

。在 littler docopt nofollow noreferrer“> Inst/示例中的littler repo 。我每天多年都使用了许多这些。正如他们所说,“为我工作”。

"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 to trailingOnly=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 and docopt in the littler repo in inst/examples. I have used a number of those daily for many years. "Works for me" as they say.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文