mauede at alice.it
2010-Feb-23 15:45 UTC
[R] how to pass external parameters to an R script
How, if possible, can I run an R script, from command line, passing external parameters just like I can run a C main program passing parameters: # Cprog p1 p2 p3 Cprog can access its arguments (p1,p2,p3) through the built-in structures "argv" and "argc". Since R is built on C language I would expect the same feature to be available with R scripts as well ... ? Please, notice that I do not mean to open an interactive R session, assign values to p1, p2, p3 and then call the R script from the same interactive session. This way I daresay that p1, p2, p3 would be known to the R script as global variables. Thank you very much. Maura tutti i telefonini TIM! [[alternative HTML version deleted]]
Hi Maura, See ?Rscript -Ista On Tue, Feb 23, 2010 at 10:45 AM, <mauede at alice.it> wrote:> How, if possible, can I run an R script, from command line, passing external parameters just like > I can run a C main program passing parameters: > > # Cprog p1 p2 p3 > > Cprog can access its arguments (p1,p2,p3) through the built-in structures "argv" and "argc". > Since R is built on C language I would expect the same feature to be available with R scripts as well ... ? > Please, notice that I do not mean to open an interactive R session, assign values to p1, p2, p3 and then > call the R script from the same interactive session. This way I daresay that p1, p2, p3 would be known to > the R script as global variables. > > Thank you very much. > Maura > > > tutti i telefonini TIM! > > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >-- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org
mauede wrote:> > How, if possible, can I run an R script, from command line, passing > external parameters just like > I can run a C main program passing parameters: > > # Cprog p1 p2 p3 > > Cprog can access its arguments (p1,p2,p3) through the built-in structures > "argv" and "argc". > Since R is built on C language I would expect the same feature to be > available with R scripts as well ... ? > Please, notice that I do not mean to open an interactive R session, assign > values to p1, p2, p3 and then > call the R script from the same interactive session. This way I daresay > that p1, p2, p3 would be known to > the R script as global variables. > > Thank you very much. > Maura > >Command line arguments can be retrieved using the commandArgs() function. For more complicated argument processing, CRAN has the getopt and optparse packages. Good luck! -Charlie -- View this message in context: http://n4.nabble.com/how-to-pass-external-parameters-to-an-R-script-tp1566077p1566487.html Sent from the R help mailing list archive at Nabble.com.