Package Relative Paths in R

半城伤御伤魂 提交于 2020-01-01 02:27:12

问题


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?


回答1:


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"))


来源:https://stackoverflow.com/questions/11977417/package-relative-paths-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!