-1

My idea is simple, I have a wrapper package that is ready to load and execute R and Python scripts (through reticulate).

Despite the requirement for a common file/code structure, the idea is that if a user wants to define a new method for the workflow (say, updated taxonomy), it would be enough to add a new script in the scripts folder (i.e., place files in rules/, py/..., and rebuild).

What is the proper way to make this work?

I've tried loading the files through .onLoad, i.e.,

.onLoad <- function(lib, pkg){
  require(reticulate) #I know require is bad practice; this is for example purposes
  files <- dir('rules')
  lapply(files, function(w){
     source(sprintf('rules/%s', w))
     source_python(sprintf("py/%s/rule.py", w))
  })
}

But this seems to be looking at local directories, rather than inside the package.

I have found that R is able to load .rda or .RData files from data/ directory, or .txt, .csv, but that's about it. What about extensions, like sourcing files as in my example?

Any help would be appreciated!

runr
  • 1,142
  • 1
  • 9
  • 25
  • If ``.rda`` files are actually a limitation due to some known reasons, one possible solution could be another wrapper, to source and pack to ``.rda`` all scripts before deploying. But, weirdly, this seems even messier that the original solution. Am I on the right track here? – runr May 02 '19 at 10:02
  • You are free to add any kind of data in `inst/extdata`. You can access to the path with `system.file("extdata", "file.ext", package="pkg")`. Is that a viable option for you? – JRR May 02 '19 at 15:22
  • @JRR Yes, it was exactly what I was looking for. You can post your comment as an answer, if you'd like. – runr May 02 '19 at 20:21

1 Answers1

1

The folder inst/exdata allows for adding any kind of data within an R package. This might be the right place to store .R or .py files not directly related to the core code of your package. You can access these files with system.file("extdata", "file.ext", package="pkg"). See also extdata in R packages.

JRR
  • 3,024
  • 2
  • 13
  • 37