0
$\begingroup$

I have successfully written an R package and want to ship it with a specific csv file. I placed the file in the data and data-raw subfolders.

read.csv("data/foobar.csv")

The above command fails. How can I read the csv file?

$\endgroup$
  • $\begingroup$ use paste0() to combine your base folder and all the csv's which you wish to read $\endgroup$ – coldy Oct 26 at 18:41
1
$\begingroup$

data-raw is for storing data alongside a short R script that will do the conversion to R data for the user, and the user will just use the data() function.[source] Alternatively, if you want the raw CSV to be user-accessible, I think you need to use the extdata folder, as documented here. Then the user can get the actual path to the file on their system, after package installation, with system.file("extdata", ..., package = "mypackage"). Then, finally, they can feed that path to read.csv() with whatever options they like.

$\endgroup$
  • $\begingroup$ extdata is what I was looking for. Thank you! $\endgroup$ – lars20070 Oct 27 at 5:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.