[Rd] Putting demo shell scripts, text files, and RScript files with a package?

Martin Maechler maechler at stat.math.ethz.ch
Wed Mar 18 08:52:51 CET 2009

>>>>> "DR" == David Rosenberg <drosen at stat.berkeley.edu>
>>>>>     on Tue, 17 Mar 2009 13:25:46 -0400 writes:

    DR> I've written a package to assist with using R in Hadoop Streaming.
    DR> The main point of the package is to help make command-line runnable  
    DR> RScript files.  I'd like to provide a demo RScript file, a demo data  
    DR> file (e.g. a plaintext file, not something already processed by R) ,  
    DR> as well as demo bash shell scripts that demonstrate how to run the job  
    DR> from the command line and in a Hadoop cluster.

    DR> My best idea so far for distributing these files is to package the  
    DR> contents of these files as a list of strings in a data file in the  
    DR> data directory, and include a function in the package, say  
    DR> generateDemoFolder(targetDir), that writes the files to a user- 
    DR> specified directory, ready for use from the command line.

I think you've overlooked the  possibility  of   <sourcePkg>/inst/

I would use something like  <sourcePkg>/inst/scripts/
which will become           <installedPkg>/scripts/

[accessible from within R  by  system.file("scripts", package= "<yourPkg>")

One "famous" example being the  R scripts for Venables&Ripley's
MASS book, available from all R installations via
     system.file("scripts", package="MASS")


 > list.files(system.file("scripts", package="MASS"))
 [1] "ch01.R" "ch02.R" "ch03.R" "ch04.R" "ch05.R" "ch06.R" "ch07.R" "ch08.R" "ch09.R"
[10] "ch10.R" "ch11.R" "ch12.R" "ch13.R" "ch14.R" "ch15.R" "ch16.R"

 > source(system.file("scripts", "ch01.R", package="MASS"))

{ which ends in an error: It's not made for source();
  it might well be source()able if  
  'if(interactive()) '     where replaced by
  'if(dev.interactive()) ' 


Martin Maechler, ETH Zurich

More information about the R-devel mailing list