Re: [R] R command execution from shell

2011-01-05 Thread Sebastien Bihorel

Thank you for this alternative. Both seem to work on my systems.

Sebastien

Prof Brian Ripley wrote:

On Tue, 4 Jan 2011, Duncan Murdoch wrote:


On 04/01/2011 3:21 PM, Sebastien Bihorel wrote:

Dear R-users,

Is there a way I can ask R to execute the write(hello
world,file=hello.txt) command directly from the UNIX shell, instead
of having to save this command to a .R file and execute this file 
with R

CMD BATCH?


Yes.  Some versions of R support the -e option on the command line to 
execute a particular command.  It's not always easy to work out the 
escapes so your shell passes all the quotes through...  An 
alternative is to echo the command into the shell, e.g.


echo 'cat(hello)' | R --slave

(where the outer ' ' are just for bash).


It is marginally preferable to use Rscript in place of 'R --slave'.
I think in all known shells

Rscript -e write('hello world', file = 'hello.txt')

will work.  (If not, shQuote() will not work for that shell, but this 
does work in sh+clones, csh+clones, zsh and Windows' cmd.exe.)




__
R-help@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.


[R] R command execution from shell

2011-01-04 Thread Sebastien Bihorel

Dear R-users,

Is there a way I can ask R to execute the write(hello 
world,file=hello.txt) command directly from the UNIX shell, instead 
of having to save this command to a .R file and execute this file with R 
CMD BATCH?


Thank you

Sebastien

__
R-help@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.


Re: [R] R command execution from shell

2011-01-04 Thread Duncan Murdoch

On 04/01/2011 3:21 PM, Sebastien Bihorel wrote:

Dear R-users,

Is there a way I can ask R to execute the write(hello
world,file=hello.txt) command directly from the UNIX shell, instead
of having to save this command to a .R file and execute this file with R
CMD BATCH?


Yes.  Some versions of R support the -e option on the command line to 
execute a particular command.  It's not always easy to work out the 
escapes so your shell passes all the quotes through...  An alternative 
is to echo the command into the shell, e.g.


echo 'cat(hello)' | R --slave

(where the outer ' ' are just for bash).

Duncan Murdoch

__
R-help@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.


Re: [R] R command execution from shell

2011-01-04 Thread Sebastien Bihorel

Thank you

That is exactly what I was looking for.

Sebastien

Duncan Murdoch wrote:

On 04/01/2011 3:21 PM, Sebastien Bihorel wrote:

Dear R-users,

Is there a way I can ask R to execute the write(hello
world,file=hello.txt) command directly from the UNIX shell, instead
of having to save this command to a .R file and execute this file with R
CMD BATCH?


Yes.  Some versions of R support the -e option on the command line to 
execute a particular command.  It's not always easy to work out the 
escapes so your shell passes all the quotes through...  An alternative 
is to echo the command into the shell, e.g.


echo 'cat(hello)' | R --slave

(where the outer ' ' are just for bash).

Duncan Murdoch


__
R-help@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.


Re: [R] R command execution from shell

2011-01-04 Thread Prof Brian Ripley

On Tue, 4 Jan 2011, Duncan Murdoch wrote:


On 04/01/2011 3:21 PM, Sebastien Bihorel wrote:

Dear R-users,

Is there a way I can ask R to execute the write(hello
world,file=hello.txt) command directly from the UNIX shell, instead
of having to save this command to a .R file and execute this file with R
CMD BATCH?


Yes.  Some versions of R support the -e option on the command line to execute 
a particular command.  It's not always easy to work out the escapes so your 
shell passes all the quotes through...  An alternative is to echo the command 
into the shell, e.g.


echo 'cat(hello)' | R --slave

(where the outer ' ' are just for bash).


It is marginally preferable to use Rscript in place of 'R --slave'.
I think in all known shells

Rscript -e write('hello world', file = 'hello.txt')

will work.  (If not, shQuote() will not work for that shell, but this 
does work in sh+clones, csh+clones, zsh and Windows' cmd.exe.)


--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@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.