How to access file inside a package function?


I need to access a file inside a package function, but I don't know hoy to indicate its route.

I am using a function (from another package) inside a package which takes the route of a json of a file as an input, so I cannot store the data in /data as a Rdata.

If I store my config json inside a directory of my package (i.e, inst/data/cfg.json), how do I access it from inside a function of my package?
When I load and run this package, it looks for it inside the working directory, not inside the directory of package...


Hi @samuelhuerga! The system.file() function can help you with this: you give it character vectors that specify paths relative to a package's root, and then you specify the package using the package argument. The included link has some examples of this.

Does that help?

1 Like


It works like a charm!

Thank you very much!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.