5

I have a SQLite database like run.sqlite in my local computer. I am making an R package which contains some code and that runs on this SQLite database. How can I make a R package which contains this database too. So, that I can share/publish my R package in CRAN/github.

  • 1
    http://r-pkgs.had.co.nz/data.html but CRAN has pkg size restrictions/guidelines so you may need to make this a separate data pkg for the sqlite file depending on how big it is. – hrbrmstr Jan 13 '17 at 05:42
  • 1
    not sure if this is a good way but maybe you could include your data as a simple .csv file in your package and add a function in your package that, given a path to some dir, makes the sqlite db there. – davidski Jan 13 '17 at 07:35

1 Answers1

3

I put an sqlite file in my R package using the method from the Raw Data section in the R package documentation.

Put your sqlite file in the folder inst\extdata\ in the package root, then in your package get the path to it using.

system.file("extdata", "sqlite.db", package = "package-name")

For example:

db_file = system.file("extdata", "sqlite.db", package = "package-name")
con = DBI::dbConnect(RSQLite::SQLite(), dbname = db_file)
Shawn
  • 336
  • 3
  • 10
  • Apparently this method will fail in a staged installation, unless the call to `system.file` is inside a function. See [here](https://stackoverflow.com/questions/63530442/how-to-use-files-in-inst-extdata-r-package-check-prevent-to-use-system-file-i) and [here](https://developer.r-project.org/Blog/public/2019/02/14/staged-install/). – jerome Oct 12 '21 at 20:38