On 09/02/2009 01:13 PM, Duncan Murdoch wrote:
Romain Francois wrote:
Hello,
(This is a remix of this previous thread:
https://stat.ethz.ch/pipermail/r-devel/2009-August/054264.html , but
with a concrete example)
I am developing some packages that contain scripts (for Rscript) and
would like to know what is the best/recommended way to ship these
scripts.
An example is the "ant" package (R capable version of apache ant, see
http://tr.im/xHLs). The package has a ant.R script in the exec
directory and here is how I use it :
$ `Rscript -e "cat( system.file( 'exec', 'ant.R', package = 'ant' ) ) " `
... not so pretty. Meanwhile, "Writing R extensions" talks about the
exec directory, but it is not clear if I can use it this way or how.
I think exec is a reasonable place to put the script. If you don't want
to type that long command above, why not put it in a small function in
the package? E.g. define
antR <- function() cat( system.file( 'exec', 'ant.R', package = 'ant' ) )
then you can run it with
Rscript -e "ant::antR()"
Duncan Murdoch
Yes. I'd have to do a bit more work to call the script with parameters.
Something like this perhaps:
antR <- function( run = FALSE){
rscript <- file.path( R.home(), "bin", "Rscript" )
ant.script <- system.file( 'exec', 'ant.R', package = 'ant' )
cmd <- sprintf( '"%s" "%s" %s',
rscript, ant.script, paste( commandArgs( TRUE), collapse = " " )
if( run ){
system( cmd )
} else {
run
}
}
...
I guess i am looking for a mechanism similar to the dispatch of CMD, but
able to dispatch within exec directories of packages :
$ R CMD exec ant ant.R
or maybe a --package switch in Rscript:
$ Rscript --package ant ant.R
or a Rexec script similar to Rscript :
$ Rexec ant/ant.R
--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/xHLs : R capable version of ant
|- http://tr.im/xHiZ : Tip: get java home from R with rJava
`- http://tr.im/xkMc : Combine R CMD build and junit
______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel