object not found error with internal package data (sysdata)

Hi
I believe I have followed the instructions in the R Packages book.
I have a lookup table that I want to serve as internal data in my package. One of the package functions needs it. But I don't need or want it to be user-visible or exported.

I have put the data generation script in a file in data-raw, and I have used usethis::use_data to install the data in R/sysdata.rda :

use_data(lookup, internal = TRUE, overwrite = TRUE)

However when I call the function that needs lookup I get the error object 'lookup' not found

I'm confused as to why the data is not being loaded so that it is internally accessible to the package. Please can anyone suggest what I am doing wrong? There is no extra step mentioned in the R Packages book that would be needed to make the data accessible. It worked fine when I had the same lookup previously as exported data, but it ought to be internal really.

I have LazyData: true in the DESCRIPTION file.

:wave: @francisbarton!

I've created a minimal package to ensure I too understand the instructions and it worked.

  • I created the package with usethis::create_package().
  • I ran usethis::use_data_raw() and edited the opened script to obtain
## code to prepare `DATASET` dataset goes here
lookup <- sample(1000)
usethis::use_data(lookup, internal = TRUE, overwrite = TRUE)
  • I ran this code.
  • I re-started R.
  • I ran usethis::use_r("bla") and edited the opened script to obtain:
bla <- function() {
  print(length(lookup))
}
  • I ran devtools::load_all() and then bla()which worked.

My assumptions on what you could have forgotten to do:

  • Maybe you didn't execute the code in data-raw? It needs to be manually executed every time you amend it, there's no automatic way I know of to "build the data".
  • Maybe you forgot to run devtools::load_all()?

I hope this helps, good luck!

1 Like

Thanks for taking the time to respond to this, @maelle.
I think the code was fine within my package/project - I had actually run the code in data-raw and re-built and re-installed the package.
When I encountered this error, I was trying to use the package data from a separate project, and I think my issue was that I needed to refresh the package to ensure the latest version was loaded.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.