[R] scan not working

peter dalgaard pdalgd at gmail.com
Sun Jan 27 12:34:12 CET 2013


On Jan 27, 2013, at 08:33 , Emily Sessa wrote:

> Hi all, 
> 
> I am trying to use the scan function in an R script that I am calling from the command line on a Mac; at the shell prompt I type: 
> 
> $ Rscript get_q_values.R LRT_codeml_output 
> 
> in the hope that LRT_codeml_output will get passed to the get_q_values R script. The first line of that script is: 
> 
> chidata <- scan(file="")
> 
> which, as I understand how scan works, will read the contents of the file from the command line into the object chidata. I did this a few times and it worked like a charm. And then, it stopped working. Now, every time I try to do this, I get "Read 0 items" as the next line in the terminal window, and the output produced by the script is empty, because it's apparently no longer reading anything in. I don't think I changed anything in the script; it just stopped being able to execute the scan function. Does anyone have any idea how to fix this?? I did not have anything else in that scan line when it was working before. I've updated R and restarted my computer in the hope that it would help, but it hasn't. Any help would be much appreciated.

I don't see how that would ever work. The 2nd and further args to Rscript are passed to R and accesible via commandArgs(). There's no way that scan() can know what the arguments are. It might work with 

Rscript get_q_values.R < LRT_codeml_output

though. Or you need to arrange explicitly for scan(file=commandArgs(TRUE)[1]).

> 
> -ES
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list