I am writing an R package which uses rjags
as a dependency. My exported functions need to call rjags::jags.model("myModel.JAGS")
internally.
I feel like I should bundle myModel.JAGS
file within the exec
folder, even if it is not a stricto-sensu "script". How should I then access it?
I find
#'@export
myFunction <- function () {
# ...
path <- path.package('myPackage')
file <- file.path(path, 'exec', 'myModel.JAGS')
rjags::jags.model(file, ...)
# ...
}
a little hackish, is it?
You should use system.file
with your package name, and put the file in the inst
folder.
Anything in inst
gets copied to the package folder when the package is installed, so if you have mypackage/inst/jags/mymodel.jags
then you can do system.file("jags","mymodel.jags",package="mypackage")
to get the path to your jags file.
Note that if you use devtools
and load your packages in development mode instead of doing an install, then devtools
will load some wrappers for system.file
to look in inst/whatever/
so anything that uses this will work for an uninstalled package loaded via load_all
.