linux - 从 shell 执行 R 脚本

标签 linux r

我正在尝试从 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

谁能解释一下这个错误信息是什么意思?

最佳答案

试试 functionName(commandArgs(trailingOnly = TRUE)[1])。在 functionName 中定义的 args 对象在函数外部不“可见”。在这里,它指向 args() 内置函数,参见 ?args

关于linux - 从 shell 执行 R 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23608334/

相关文章:

linux - EPOLLONESHOT 是否阻止在对 epoll_wait() 的单个调用中返回单个描述符上的多个事件?

r - R 中的数据表 : the columns to join by must be specified using 'on=' argument error

R:将函数应用于以向量元素作为参数的矩阵

linux - 阻塞信号

r - 如何更改grid.draw的位置

r - 从一大组数据帧中产生均值的平均值、标准差和标准误差

r - 在 Ubuntu 14.04LTS 上安装 Pandoc 以与 R Markdown 一起使用时出现问题

c - 为什么使用 timer_settime() 会影响 sleep() 函数

linux - 关于 SSH : Are there something related with default login name?

c - watchdog_fire 中的 usermodehelper API 调用