0

I am just learning R and I am really baffled by the outcome of these lines in my R script:

myfunction <- function(pdbid,t,d,tabledir) {
    command <- sprintf("sh ../addMeta.sh %s/tool%d-*-data%d-*/%s*.stats-table | tail -n +2",tabledir,t,d,pdbid)
    print(command)
    result <- read.table(pipe(command))
}

The above function is run for multiple instances of the parameter "pdbid" like this:

t3 <- apply(pdbids, 2, function(x) myfunction(as.character(x),t,d,as.character("somedironmymachine")))

When I run the R script, I get an error:

Error in pipe(command) : invalid 'description' argument

Googling this message lead me to two very different problems on Stack Overflow, and no enlightenment about what this message means. However, I thought it must be something with the pipe, took a look at the command in the pipe, that's why I print it above, and it looks good

[1] "sh ../5_runs/addMeta.sh ../5_runs/10-subopts-layers-alltools//tool2-*-data4-*/1DK1*.stats-table | tail -n +2"
[2] "sh ../5_runs/addMeta.sh ../5_runs/10-subopts-layers-alltools//tool2-*-data4-*/1ET4*.stats-table | tail -n +2"
[3] "sh ../5_runs/addMeta.sh ../5_runs/10-subopts-layers-alltools//tool2-*-data4-*/1F1T*.stats-table | tail -n +2"
[4] "sh ../5_runs/addMeta.sh ../5_runs/10-subopts-layers-alltools//tool2-*-data4-*/1I6U*.stats-table | tail -n +2"
[..]

and each of these commands runs without problems on the commandline outside R.

$ sh ../5_runs/addMeta.sh ../5_runs/10-subopts-layers-alltools//tool2-*-data4-*/2GDI*.stats-table | tail -n +2
-> correct result table from addMeta.sh

Even inside R it runs fine if I call it with system(command) - so what's wrong for pipe? Also, in the past I used the pipe(command) approach for very similar (special characters, chained commands) commands before and it worked as expected, though I never used it calling repeatedly via apply.

How can I further debug this problem? Am I using apply wrongly? If so, why is the command output correctly and runs without errors? Could it be some conversion/data format issue? If so, why does it work with system(), but not pipe()? Is there a way to use the output of system() to read in data as a workaround? Are there restrictions for pipe() in R that I am not aware of? What does the mysterious error message invalid 'description' argument mean exactly?

linse
  • 886
  • 6
  • 5
  • 1
    You'll get more help if you provide reproducible code and data as explained in [this post](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – SlowLearner Sep 16 '13 at 21:57
  • I solved the problem for now by preprocessing my data in a shell script. Thanks for the helpful pointer to the minimal example explanation, it will be of good use for me in the future. – linse Sep 30 '13 at 17:04

0 Answers0