Skip to content
Back to formatted view

Raw Message

Message-ID: <7229BBA9-0901-4D74-A6B7-E9BB0479E4C2@ucl.ac.uk>
Date: 2007-12-19T14:32:28Z
From: Jon Clayden
Subject: Standard input and R

Dear all,

I am trying to wrap a *nix shell script around R for a particular  
purpose, for which I need to get R to execute predetermined commands  
but retain interactivity and allow user input during their execution.  
A straight redirection of standard input is therefore not appropriate,  
and I don't think "littler" is the solution because I don't want to  
write an independent R script.

What I want is effectively something like what ruby does with the '-e'  
option:

$ ruby -e 'gets'
<waits for input from terminal>

R seems to accept an '-e' option too, even though I can't see it  
mentioned in the output from 'R -h', but it doesn't work the same:

$ R --slave --vanilla -e 'scan(what=character(0),nlines=1,quiet=T)'
character(0)
$

The only way I can get this to work is by creating an .Rprofile file  
containing the commands I want to run, but this is suboptimal for a  
number of reasons: I have difficulties if an .Rprofile already exists  
in the working directory, the default packages are not loaded, and the  
process doesn't quit if stop() is called.

I have a vague inkling that this may be achievable with a  
pseudoterminal (pty) or named pipe, but if anyone knows a simpler  
route I'd be glad to avoid getting involved in that kind of thing...

Many thanks in advance.
Jon