Re: [Rd] Referencing 'inst' directory in installed package

From: Dirk Eddelbuettel <edd_at_debian.org>
Date: Wed, 17 Aug 2011 07:49:26 -0500

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/ itself.

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
http://dirk.eddelbuettel.com/blog/2011/08/04#rcpp_classes_2011-09_and_2011-10
http://www.revolutionanalytics.com/products/training/public/rcpp-master-class.php

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Wed 17 Aug 2011 - 12:51:31 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 17 Aug 2011 - 13:00:18 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive