Chris Mcnally
Chris Mcnally

Reputation: 176

Importing dynamic datasets within a {golem} package

I currently have a data_prep.R file that I use to pull in data using SQL queries and then wrangle the data into suitable data frames for use within my {golem} package. At the end of this script I have

usethis::usedata(df, overwrite = T)

From research it seems that this file should go into the /data-raw folder as you are not supposed to execute code in the /R folder. When ran, it constructs my data frames and then places them within the /data folder. However, this script does not seem to get ran whenever I run the application, moreover, the data frames will remain unchanged until I manually run the data_prep.R script again.

My application relies on the new data coming in and as such I would need this data_prep.R file to run whenever the app is launched.

Is there something that I am missing?

Upvotes: 0

Views: 720

Answers (2)

Chris Mcnally
Chris Mcnally

Reputation: 176

I worked this out by placing the data_prep.R script into the application base directory and sourcing the file within the app_server.R file.

source("./data_prep.R")

This runs the script on app start and pulls the data frames from the server allowing the data to be up to date.

Upvotes: 2

Damien Georges
Damien Georges

Reputation: 126

The call of usethis::usedata(df, overwrite = T) create you a dataset you can load when your package is in use. You should load explicitly the dataset in your app using data(df) in the piece of code where the data is needed.

Upvotes: 0

Related Questions