简体   繁体   English

从shell执行R脚本

[英]Executing R script from shell

I am trying to call an R script from a shell. 我试图从shell调用R脚本。

The script looks like this: 该脚本如下所示:

functionName <- function(file1){
  args <- commandArgs(trailingOnly = TRUE)
  print(args)
  data <- read.table(file(file1),row.names=1,header=FALSE,sep='\t',dec='.')}


functionName(args[1])

my file1 contains rows of numbers like: 我的file1包含数字行,如:

1 2 1 2 4
2 4 5 4 2
1 2 3 4 5

However, calling this script from the shell: 但是,从shell调用此脚本:

Rscript scriptName fileName

I get the following error: 我收到以下错误:

Error in args[1] : object of type 'closure' is not subsettable
Calls: processGroups -> read.table -> file
Execution halted

Can anyone explain what this error message means? 谁能解释一下这个错误信息是什么意思?

Try functionName(commandArgs(trailingOnly = TRUE)[1]) . 尝试functionName(commandArgs(trailingOnly = TRUE)[1]) args object defined in functionName is not "visible" outside the function. functionName定义的args对象在functionName外部不是“可见的”。 Here, it points to the args() builtin function, see ?args . 在这里,它指向args()内置函数,参见?args

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

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