Jonathan Malmaud
2011-Aug-17 03:17 UTC
[Rd] Referencing 'inst' directory in installed package
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? Thanks, Jon Malmaud
Kasper Daniel Hansen
2011-Aug-17 12:29 UTC
[Rd] Referencing 'inst' directory in installed package
On Tue, Aug 16, 2011 at 11:17 PM, Jonathan Malmaud <malmaud at gmail.com> 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?The inst directory does not exists after installation (this is described in R-exts). Use something like system.file("extdata", package = "MyPackage") to locate a directory etc. Kasper> > Thanks, > Jon Malmaud > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >
Marc Schwartz
2011-Aug-17 12:35 UTC
[Rd] Referencing 'inst' directory in installed package
On Aug 16, 2011, at 10:17 PM, 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? > > Thanks, > Jon MalmaudSee ?path.package and ?file.path Example:> require(WriteXLS)Loading required package: WriteXLS # I am on OSX> path.package("WriteXLS")[1] "/Library/Frameworks/R.framework/Versions/2.13/Resources/library/WriteXLS" I have Perl scripts in my package, which are in the /inst/Perl folder in the package source, so:> file.path(path.package("WriteXLS"), "Perl/WriteXLS.pl")[1] "/Library/Frameworks/R.framework/Versions/2.13/Resources/library/WriteXLS/Perl/WriteXLS.pl" HTH, Marc Schwartz
Dirk Eddelbuettel
2011-Aug-17 12:49 UTC
[Rd] Referencing 'inst' directory in installed package
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
You can use system.file(package="your_package_name") which will return you library directory. -----Original Message----- From: r-devel-bounces at r-project.org [mailto:r-devel-bounces at r-project.org] On Behalf Of Jonathan Malmaud Sent: 17 August 2011 04:18 To: r-devel at r-project.org Subject: [Rd] Referencing 'inst' directory in installed package 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? Thanks, Jon Malmaud ______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel LEGAL NOTICE This message is intended for the use o...{{dropped:10}}