1

I am trying to call an R script from a shell.

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:

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

However, calling this script from the 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?

1
  • 1
    It helps understanding this error message if you know that a 'closure' is a type of function in R (see help("closure")), i.e., not a data object. Commented May 12, 2014 at 12:12

1 Answer 1

3

Try functionName(commandArgs(trailingOnly = TRUE)[1]). args object defined in functionName is not "visible" outside the function. Here, it points to the args() builtin function, see ?args.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.