[Rd] Referencing 'inst' directory in installed package

Dirk Eddelbuettel edd at debian.org
Wed Aug 17 14:49:26 CEST 2011

On 16 August 2011 at 23:17, Jonathan Malmaud wrote:
| Hi,
| My R package has files in the 'inst' directory that it needs to reference. How can the R scripts in my package find out the full path to the 'inst' directory after the package is installed, given that different users may have installed the package to different libraries? 

It is slightly different:  files and directories below the inst/ directory in
the _sources_ will be installed in the toplevel diretory of the _installed package_.

You can then use system.file() to get the location at run-time for the
installed package. E.g. to get the example file 'fib.r' from the Fibonacci
directory within the examples of Rcpp of my installed version:

R> system.file(package="Rcpp", "examples", "Fibonacci", "fib.r")
[1] "/usr/local/lib/R/site-library/Rcpp/examples/Fibonacci/fib.r"

The result of that system.file() call could now be fed to source() etc. 

system.file() can be used for other files within the package too. 'Writing R
Extensions' details what other files are installed by default -- but as
stated, everything below inst/ gets copied as is, without the layer of inst/

Hope this helps,  Dirk

Two new Rcpp master classes for R and C++ integration scheduled for 
New York (Sep 24) and San Francisco (Oct 8), more details are at

More information about the R-devel mailing list