[Rd] exec subdirectory of a package

Romain Francois romain.francois at dbmail.com
Fri Aug 7 15:15:13 CEST 2009


Anyone ?

I guess I'll have to make a package that ships the execute script

Romain

On 08/05/2009 11:32 AM, Romain Francois wrote:
> Hello,
>
> WRE contains the following information about the "exec" subdirectory of
> a package :
>
> "Subdirectory exec could contain additional executables the package
> needs, typically scripts for interpreters such as the shell, Perl, or
> Tcl. This mechanism is currently used only by a very few packages, and
> still experimental."
>
> I think it would be useful to expand "very few". For example "tcltk"
> uses it.
>
> But the real questions are;
> - can this be used in conjunction with "R CMD", something like
>
> $ R CMD execute package script parameters
>
> The alternative used in a few packages (Rserve, Roxygen, ...) is to add
> a file in ${R_HOME}/bin, but I am not sure this works with binary builds
> of packages
>
> - can the script be an R script, in that case would a shebang like this
> be enough :
>
> #!/bin/env Rscript
>
> definitely works on (at least my) linux
>
> A very naive "execute" written in R follows.
>
> Romain
>
>
>
>
> #!/bin/env Rscript
>
> args<- commandArgs(TRUE)
> if( length(args)<  2 ){
>           stop( "usage : R CMD execute package script [parameters]\n" )
> }
>
> package<- args[1]
> script<- args[2]
> scriptfile<- file.path( system.file( "exec", script, package = package ) )
> if( !file.exists( scriptfile ) ){
>           stop( sprintf( "file not found: '%s' ", scriptfile  ) )
> }
>
> trail<- if( length(args)>  2 ) paste( tail( args, -2 ), sep = " " ) else ""
> cmd<- sprintf( '"%s" %s', scriptfile, trail )
> system( cmd )


-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/vzip : Code Snippet : List of CRAN packages
|- http://tr.im/vsK1 : R parser package on CRAN
`- http://tr.im/vshK : Transfer files through Rserve



More information about the R-devel mailing list