[R] loading a package .Rda file at package load time
cls59
chuck at sharpsteen.net
Mon Sep 14 21:28:44 CEST 2009
Hi, I have seen the answer to this sometime before but I just can't find it
again - pointers appreciated.
I have a package that contains some data.frames saved as .Rda files in the
data/ directory. When the package is loaded I would like to have them be
available in the workspace (without the user having to explicitly load them
using data(...)).
If my package does not use a NAMESPACE, I can place data(varName) in
.First.lib. However if I use NAMESPACES then the above line will fail when
placed in .onLoad. I was thinking of doing something such as
load'filename.Rda') but that would require me to know the path to the
package in a platform independent way.
Can anybody suggest how I can acheive this?
Thanks,
--
Rajarshi Guha
</quote
You mentioned that you used something similar to:
.First.lib <- function( libname, pkgname ){
data( varName )
}
And it didn't work when you attached a NAMESPACE to the package. If your
.Rda files are stored in the data directory of the package, have you tried
using:
.First.lib <- function( libname, pkgname ){
data( varName, package = pkgname )
}
If that doesn't work, then system.file() may be used to explicity recover
the location of your package data files:
.First.lib <- function( libname, pkgname ){
data( system.file( 'data/myDataFile.Rda', package = pkgname )
}
Good luck!
-Charlie
-----
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
--
View this message in context: http://www.nabble.com/loading-a-package-.Rda-file-at-package-load-time-tp25439508p25441073.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list