【发布时间】:2014-05-12 11:53:49
【问题描述】:
我正在尝试从 shell 调用 R 脚本。
脚本如下所示:
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])
我的文件 1 包含数行,例如:
1 2 1 2 4
2 4 5 4 2
1 2 3 4 5
但是,从 shell 调用这个脚本:
Rscript scriptName fileName
我收到以下错误:
Error in args[1] : object of type 'closure' is not subsettable
Calls: processGroups -> read.table -> file
Execution halted
谁能解释这个错误信息是什么意思?
【问题讨论】:
-
如果您知道“闭包”是 R 中的一种函数(参见
help("closure")),即不是数据对象,则有助于理解此错误消息。