diff --git a/_drakeCleanFeeders.R b/_drakeCleanFeeders.R index d914fad43611a6b5a84ddc855076e820725c0381..f58757e31956474fd898a3e4759af9b4323e5b3b 100644 --- a/_drakeCleanFeeders.R +++ b/_drakeCleanFeeders.R @@ -1,12 +1,15 @@ # basic _drake.R style file -# but adapted for use in a project with multiple plans +# but adapted for use in a project where there might be multiple plans in the same folder +# called using r_make() from make_cleanFeeders.R +# see https://books.ropensci.org/drake/projects.html#usage for explanation + +# Libraries/Packages ---- +# the drake book suggests putting this in packages.R but... -# Libraries ---- library(dataCleaning) # remember to build it first :-) dataCleaning::setup() # load env.R set up the default paths etc makeLibs <- c("data.table", # data munching - "drake", # for plans "here", # here "lubridate", # dates and times "hms", # times @@ -17,7 +20,7 @@ makeLibs <- c("data.table", # data munching dataCleaning::loadLibraries(makeLibs) # Parameters ---- -updateData <- "yep" # edit this in any way (at all) to get drake to re-load the data +updateData <- "rerun" # edit this in any way (at all) to get drake to re-load the data updateReport <- "yes" # edit this in any way (at all) to get drake to re-load the data # Some data to play with: @@ -32,6 +35,7 @@ authors <- "Ben Anderson & Ellis Ridett" # Functions ---- # for use in drake +# the drake book suggests putting this in functions.R but... addSeason <- function(dt,dateVar,h){ dt <- dt[, tmpM := lubridate::month(get(dateVar))] # sets 1 (Jan) - 12 (Dec). May already exist but we can't rely on it @@ -79,7 +83,10 @@ getData <- function(f,updateData){ makeUniq <- function(dt){ # we suspect there may be duplicates by feeder_ID, dateTime & kW # remove them (report this in the .Rmd) - uniq <- unique(dt, by = c("rDateTime", "feeder_ID", "kW")) + uniq <- unique(dt, by = c("rDateTime", # dateTime + "feeder_ID", # our constructed unique feeded ID + "kW") # kW + ) return(uniq) } @@ -150,6 +157,8 @@ makeReport <- function(f,version, type = "html", updateReport){ # Set the drake plan ---- +# the drake book suggests putting this in plan.R but... +# I had expected r_make() to load drake() in the new clean R session but it doesn't my_plan <- drake::drake_plan( origData = getData(dFile, updateData), # returns data as data.table. If you edit 'update' in any way it will reload - drake is watching you! uniqData = makeUniq(origData), # remove duplicates @@ -162,4 +171,5 @@ my_plan <- drake::drake_plan( ) # see https://books.ropensci.org/drake/projects.html#usage -drake_config(my_plan, verbose = 2) \ No newline at end of file +# I had expected r_make() to load drake() in the new clean R session but it doesn't +drake::drake_config(my_plan, verbose = 2) \ No newline at end of file