Actually, I'm going to take by my comments.

You can use Rscript with multiple -e arguments to do what I was looking for:

Rscript -e 'library(broadgap.hapmaptools)' -e 'processAllFiles(dir="/ humgen/cnp04/sandbox/steve/1m/hapmap3/genotypes/ftp.hapmap.org/genotypes/2008-07_phaseIII/hapmap_format/forward ", outRootDir="/humgen/cnp04/sandbox/data/snpTagging")'

Thanks for the pointer on getopt - it's much nicer than my homebrew solution.

-Jim

On Jun 18, 2009, at 1:54 PM, Jim Nemesh wrote:

I did look at ?Rscript.  My question there was:
Unfortunately, it looks like each expression is evaluated separately.
Is there a way to evaluate multiple expressions in the same
environment to make the above work?

I could write an Rscript client file, but it's still poor CLI support compared to other languages, and I still have to distribute an Rscript client. I'd like to just load a library and make 1 call to it on the command line. Is there any way to do that with the -e param?

-Jim

On Jun 18, 2009, at 1:39 PM, Gabor Grothendieck wrote:

See the getopt R package and have a look at ?Rscript

Also on Windows see Rscript.bat and #Rscript.bat in
http://batchfiles.googlecode.com

and on Linux see:
http://dirk.eddelbuettel.com/code/littler.html

On Thu, Jun 18, 2009 at 1:25 PM, Jim Nemesh<nem...@broad.mit.edu> wrote:
I develop quite a bit of R code that I tend to distribute, or let
other people embed in their software.  One of the things I'd really
like to do is find a way to load an R library I've developed, and call
one function with arguments.

Currently, I achieve that by building a separate R client file, which reads in the command line arguments, loads the library, and calls the main function. The commandLineArgs function below uses commandArgs(),
and searches the vector for the keys/values to make life easier.

(code available at inside "birdsuite executables" at 
http://www.broad.mit.edu/science/programs/medical-and-population-genetics/birdsuite/birdsuite-downloads-0)

Example:
---
library (broadgap.utils)
pedigreeFile<-commandLineArg("pedigreeFile", verbose=T)
outPedigreeFile<-commandLineArg("outPedigreeFile", verbose=T)
relabelPedigree(pedigreeFile, outPedigreeFile)
---
called by:

R CMD BATCH --pedigreeFile="foo" --outPedigreeFile="bar"
example_client.R

What I'd like to do is find a way to achieve the above, but without
writing the client file, so I can avoid distributing these wrapper
client files. While the above works, it's not terribly robust, and a
user needs to know what they are doing. To make this robust, there
would have to be a fair bit of work to properly validate arguments,
and print help files appropriately. Python would be an obvious choice
for writing CLI's, as it has great CLI support and is easy to
distribute and build executables.

I've looked at the following options:

RPy (setup is difficult, some users don't even know R, much less being
capable of the setup required here, which looks like it needs root)
RSPython (same problems as RPy)

These are reasonable for me to use for my own personal fooling around,
but not for distributing software to 1000's of users.

Rscript looks like it could be a possibility:
>Rscript -e 'library(broadgap. utils)' -e 'ls()'
character(0)

Unfortunately, it looks like each expression is evaluated separately.
Is there a way to evaluate multiple expressions in the same
environment to make the above work?  If so, I could then wrap R in
whatever language of choice I'd like, and only have to make a user
install a library.

Are there other options I'm missing?

Thanks for help/input on this.

-Jim Nemesh
      [[alternative HTML version deleted]]

______________________________________________
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-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-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.

Reply via email to