Search code examples
pythonrr-packagereticulatefile-structure

Having Python Files in an R package- Where do I put it?


I am working on a R package and for various reasons I need to write some code in Python.

For my current workflow I have the various scripts sitting in the root directory which I run in my various R codes with reticulate::py_run_file() followed by reticulate::py$my_function() (not ideal, I know).

So my question is:

Where do I place my Python files when developing an R package?


Solution

  • One option would be to put them under inst/python. The spacyr package has python files there for example.

    Another option is the exec/ directory.

    To quote from R Packages:

    exec/: for executable scripts. Unlike files placed in other directories, files in exec/ are automatically flagged as executable. Empirically, to the extent that R packages are shipping scripts for external interpreters, the inst/ directory seems to be the preferred location these days.