Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Package Relative Paths in R

Tags:

r

r-package

I've written a few functions for a package that use relative paths like:

"./data/foobar.rds"

Here's an example function:

foo <- function(x) { 
x <- readRDS("./data/bar.rds")
return(x)
}

Now, if I were to be working in the development path of the package, this works as I expect. But when I load the package, this path uses the current working directory rather than the relative path of the package.

How does one set it up such that the path for functions within a package maintain their within the package relative paths?

like image 483
Brandon Bertelsen Avatar asked Aug 15 '12 21:08

Brandon Bertelsen


1 Answers

As Andrie notes, you can use system.file, which "finds the full file names of files in packages etc."

x <- readRDS(system.file("help", "aliases.rds", package="MASS"))
like image 67
Josh O'Brien Avatar answered Nov 14 '22 19:11

Josh O'Brien