[BioC] R CMD --args

Steffen Moeller moeller at inb.uni-luebeck.de
Tue Apr 11 09:41:05 CEST 2006


It may not be the nicest of all possible solutions but has some practical 
value for me. You can cat a script through sed and into R. From the Unix 
shell you can do:

echo 'cat(file=SOMEFILENAME,"hello world")' | \
	sed -e 's/SOMEFILENAME/"hello.txt"/' | /usr/bin/R > /dev/null

The "echo" is the UNIX command, the "cat" is the R function. If you need the
output then one can redirect it to some file.

commandArgs would do for the example above and for most other cases, I 
personally find the above easier as it does not require argument parsing and 
it has some particular charm when combined with Makefiles. But commandArgs is 
the way to do it right, I am afraid.

Best regards

Steffen

Am Montag 10 April 2006 18:43 schrieb Weiwei Shi:
> You can also try this way:
> arg_variable1 = arg1
> export arg_variable1
> in linux command and then get them by using the following in R:
> arg1 <- Sys.getenv("arg_variable1")
>
> HTH,
>
> weiwei
>
> On 4/10/06, D.Enrique ESCOBAR ESPINOZA <escobarebio at yahoo.com> wrote:
> > anyone knows how to use
> > arguments in R,
> > I use linux and the comand line only...
> > i would like to pass arguments in R like we do in perl
> > ex= perl myProgram.pl arg1 arg2 ... argn



More information about the Bioconductor mailing list