I am building a R package that uses a Python script which in turn loads internal data. Both the py-script (load_csv.py
) as well as the data (data.csv
) are located in the inst/
folder of the package directory.
import pandas as pd
my_df = pd.read_csv("inst/data.csv")
The idea is to run the py-script when a R-function (rfunction
) is called:
rfunction <- function() {
reticulate::py_run_file(system.file("load_csv.py", package = "mypkg"))
}
After building the package and calling the r-function rfunction()
I get the following error:
Error: FileNotFoundError: [Errno 2] No such file or directory: 'inst/data.csv'
How can I resolve this error? Is there maybe a system call that I can place within the py-script (analogous to system.file
in R)?