I am currently developing a Golem Shiny app. Since it relies on a massive amount of raw data that needs transformation before use, I have separated this part of the workflow into a dedicated package for data preparation.
The preparation package is almost complete, and I can export all transformed data as a data.rda
file, which contains everything required by the Shiny app.
I have read Section 7.2 (Internal Data) from R Packages (2e) by Hadley Wickham many times. While I am comfortable using usethis::use_data(internal_this, internal_that, internal = TRUE)
within a single package, I am unsure how to handle a situation like mine—where the data.rda
file comes from another package but is meant to be used internally in the Shiny app package, and the shiny package itself also have an internal .rda
for intra-package purposes.
My current approach is:
data.rda
file to the R/
folder of the Shiny app package.Load_data.R
file that contains only one line of code load(file = file.path("R", "data.rda"))
to load objects from data.rda
.This seems to work, as the app can access the data. However, is this the correct approach? If not, what would be a more robust solution?
Any comment would be greatly appreciated!
According to Writing R Extensions, section 1.1.5:
The
R
subdirectory contains R code files, only.
There's an exception for sysdata.rda
, and .in
files, but nothing else.
That would indicate that using R/data.rda
would not be acceptable.
Instead, you could export the prepared data (or the data preparation function)
from your private data preparation package, and bake the results into sysdata.rda
for your primary package.
For reproducibility, write a script for those steps. In data-raw/sysdata.R
:
internal_this <- ...
internal_that <- ...
data("prepared_data", package = "rpackageforpreparingdata")
# Or: prepared_data <- rpackageforpreparingdata::prepare_data()
usethis::use_data(internal_this, internal_that, prepared_data, internal = TRUE)