Ulrike Grömping
2015-Feb-16 11:37 UTC
[R] How do I provide path character string to extdata content?
Dear helpeRs, I have some png files in the inst/extdata directory of a package (e.g., man.png), and I want to provide character strings containing the paths to these files; of course, these path strings have to depend on the individual installation. So far, I have written a function that - if called - writes the correct strings to the global environment, but that is not CRAN compatible. Ideally, I want the package namespace to export these text strings. I have played with .onLoad without luck. I do not have a good understanding of which hook is for which purpose. How can I go about this? Best, Ulrike
Duncan Murdoch
2015-Feb-16 13:40 UTC
[R] How do I provide path character string to extdata content?
On 16/02/2015 6:37 AM, Ulrike Gr?mping wrote:> Dear helpeRs, > > I have some png files in the inst/extdata directory of a package (e.g., > man.png), and I want to provide character strings containing the paths to > these files; of course, these path strings have to depend on the individual > installation. So far, I have written a function that - if called - writes > the correct strings to the global environment, but that is not CRAN > compatible.The system.file() function does this. For example, if your package named foo contains inst/fig/man.png, you would use system.file("fig/man.png", package="foo").> > Ideally, I want the package namespace to export these text strings. I have > played with .onLoad without luck. I do not have a good understanding of > which hook is for which purpose. How can I go about this?Rather than exporting the strings, it's easier to export a function that produces the strings, e.g. fig <- function(name) system.file(file.path("fig", name), package="foo") to be called as fig("man.png") Duncan Murdoch