[R] R as a `script'

Barry Rowlingson B.Rowlingson at lancaster.ac.uk
Wed Feb 5 18:28:03 CET 2003


Thomas Lumley wrote:

> or more elegantly in a single file as
> #!/bin/sh
> echo "library(tools);Sweave('"$1"')" | /usr/local/bin/R --vanilla --silent
> 

What's more elegant than a 'here' document?

#!/bin/sh
R --slave --vanilla "$@" <<EOF

print(commandArgs())
x <- runif(1000)
print(mean(x))

EOF

  - save to a file, make executable, run. It even handles command line 
arguments (the "$@" bit) which can be picked up by commandArgs().


Baz




More information about the R-help mailing list