Re: [R] [Rd] R as shell script

From: François Pinard <pinard_at_iro.umontreal.ca>
Date: Sat 15 Jul 2006 - 03:17:08 EST

[Juha Vierinen]
>Hi,

Hello, Juha. Your request, quoted below, is likely more appropriate for R help than for R devel, so I'm redirecting this reply there.

>I am considering if I should invest in learning R. Based on the
>language definition and introductory documents, it seems nice. But now
>I am faced with a problem: I want to be able to run R programs easily
>from the unix shell, and write scripts that can automatically select R
>as the interpreter:

>#!/usr/bin/R
>cat("Hello world.\n")

>This of course doesn't work, because /usr/bin/R is a shell script.

>I have been able to create a binary wrapper that calls R with the
>correct arguments, which is documented here:

>http://kavaro.fi/mediawiki/index.php/Using_R_from_the_shell

>This still lacks eg. standard input (but I have no idea how I can
>implement it in R) and full command line argument passing (can be
>done), but am I on the right track, or is there already something that
>does what I need?

I'm often using something like:

   #!/bin/sh
   R --slave --vanilla <<EOF

   # Your R source code goes here!

   EOF Within your script, shell substitution for $1, etc., will occur. So with a bit of imagination, you can do about anything :-). Simple enough! Make sure you `cat' or `print' explicitly whatever has to be written on standard output: for one, I usually prefer full control in scripts over automatic printing of given expressions.

-- 
François Pinard   http://pinard.progiciels-bpi.ca

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Sat Jul 15 03:28:03 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 15 Jul 2006 - 04:15:19 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.