[R] scan not working
Steve Lianoglou
mailinglist.honeypot at gmail.com
Sun Jan 27 20:49:25 CET 2013
Hi,
It sounds like you just want to write a command line script using R
and you would pass the suffix/prefix as command line args, no?
Why not just go with what Peter has already suggested with
`commandArgs`, or if you want a more feature-rich command line arg
parser, you can try:
http://cran.r-project.org/web/packages/optparse/index.html
If the command line argument thing won't work for you, perhaps you can
elaborate more? For instance, you mention that you know how you might
do "this" in Perl ... perhaps you can clarify "this" a bit more.
-steve
On Sun, Jan 27, 2013 at 12:27 PM, Emily Sessa <sessa.emily at gmail.com> wrote:
> Hello all (again),
>
> I received a very helpful answer to this question, and would like to pose one more:
>
> Right now I have this script, which is being called from the command line, writing output to two generically named files ("pvalues" and "qvalues") that are named in the script using the line:
>
> write(pvalues, file="pvalues", ncol=1)
> write(adjusted, file="qvalues", ncol=1)
>
> However, ideally I would like those two files to have something appended to their names that make them separate from one another, so I can identify which input they went with and so they won't write over each other when I script this into a Perl pipeline that will process many input files, which is my ultimate goal. I know how to do this in Perl, but not R... is there some way I can add another argument on the command line that will get passed to the R.script, like a simple letter code (e.g. "cro"), and then have it append that to the output file names, so they are, for example: "qvalues_cro" and "pvalues_cro"?
>
> Thank you very much,
> Emily
>
> On Jan 27, 2013, at 4:34 AM, peter dalgaard <pdalgd at gmail.com> wrote:
>
>>
>> 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.
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
--
Steve Lianoglou
Graduate Student: Computational Systems Biology
| Memorial Sloan-Kettering Cancer Center
| Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact
More information about the R-help
mailing list