Rscript:将路径文件定义为参数

发布于 2024-08-16 13:54:25 字数 751 浏览 4 评论 0原文

我尝试这个命令:

Rscript "/Users/test/Scripts/arg_test.R" "path_in=/Users/test/GR/web-app/Rproject/Inputs/Rmerge/Description.csv" path_in2="/Users/test/IdeaProjects/Rproject/Inputs/Rmerge/Template_Auto.csv"

但我有这个错误: parse(text = args[[i]]) 中的错误:

Rscript 的“path_in=/”部分中出现意外的“/”:

args=(commandArgs(TRUE))

if(length(args)==0){
    print("No arguments supplied.")
}else{
    for(i in 1:length(args)){
         eval(parse(text=args[[i]]))
    }
}


path_out = "/Users/test/Rproject/Results/"

annotation = read.csv(paste(path_in, sep=""))

modules = read.csv(paste(path_in2, sep=""))

merge_output = merge(annotation, modules, by = "Module")

如何将 path_in 定义为参数(args)?

谢谢。

I try this command :

Rscript "/Users/test/Scripts/arg_test.R" "path_in=/Users/test/GR/web-app/Rproject/Inputs/Rmerge/Description.csv" path_in2="/Users/test/IdeaProjects/Rproject/Inputs/Rmerge/Template_Auto.csv"

but I have this error :
Error in parse(text = args[[i]]) : unexpected '/' in "path_in=/"

Part of Rscript :

args=(commandArgs(TRUE))

if(length(args)==0){
    print("No arguments supplied.")
}else{
    for(i in 1:length(args)){
         eval(parse(text=args[[i]]))
    }
}


path_out = "/Users/test/Rproject/Results/"

annotation = read.csv(paste(path_in, sep=""))

modules = read.csv(paste(path_in2, sep=""))

merge_output = merge(annotation, modules, by = "Module")

How can I define path_in as argument(args) ?

Thank you.

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

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

发布评论

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

评论(3

南…巷孤猫 2024-08-23 13:54:25

用正确的赋值运算符 <- 替换 = 并用单引号保护每个参数对我来说很有效:

Rscript /tmp/RscriptArgs.R  \
  'path_in<-"/Users/test/GR/web-app/Rproject/Inputs/Rmerge/Description.csv"'  \
  'path_in2<-"/Users/test/IdeaProjects/Rproject/Inputs/Rmerge/Template_Auto.csv"'

其中 /tmp/RscriptArgs.R是您从脚本中显示的内容。

Replacing the = with the proper assignment operator <- and protecting each argument with single quotes works for me:

Rscript /tmp/RscriptArgs.R  \
  'path_in<-"/Users/test/GR/web-app/Rproject/Inputs/Rmerge/Description.csv"'  \
  'path_in2<-"/Users/test/IdeaProjects/Rproject/Inputs/Rmerge/Template_Auto.csv"'

where /tmp/RscriptArgs.R is what you showed from your script.

只为守护你 2024-08-23 13:54:25

双引号内有 path_in=,但双引号内有 path_in2=。这可能是问题所在吗?

You have path_in= inside the double quotes, but path_in2= outside. Could this be the problem?

娇俏 2024-08-23 13:54:25

谢谢,我刚刚解决了我的问题!

我应该使用“path_in='/Users/test/...'”而不是“path_in=/Users/test/...”。
与报价一起工作正常。

Rscript "/Users/test/Scripts/arg_test.R" "path_in='/Users/test/GR/web-app/Rproject/Inputs/Rmerge/Gene-level Description for Modules.csv'" "path_in2='/Users/test/IdeaProjects/Rproject/Inputs/Rmerge/Template_Auto.csv'"

由 Dirk 修复的 add 也可以正常工作(谢谢)!

Thank you, I just fix my problem !

I should use "path_in='/Users/test/...'" and not "path_in=/Users/test/...".
Works fine with quote.

Rscript "/Users/test/Scripts/arg_test.R" "path_in='/Users/test/GR/web-app/Rproject/Inputs/Rmerge/Gene-level Description for Modules.csv'" "path_in2='/Users/test/IdeaProjects/Rproject/Inputs/Rmerge/Template_Auto.csv'"

Fix add by Dirk works fine too (thanks) !

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