Skip to content
Snippets Groups Projects
Commit d2b03cc4 authored by B.Anderson's avatar B.Anderson
Browse files

removed drake from inside the _drakeXX file

parent 8e8ba05f
No related branches found
No related tags found
2 merge requests!3merge a few edits,!2fixed pdf build
This commit is part of merge request !3. Comments created here will be created in the context of that merge request.
# basic _drake.R style file # 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 :-) library(dataCleaning) # remember to build it first :-)
dataCleaning::setup() # load env.R set up the default paths etc dataCleaning::setup() # load env.R set up the default paths etc
makeLibs <- c("data.table", # data munching makeLibs <- c("data.table", # data munching
"drake", # for plans
"here", # here "here", # here
"lubridate", # dates and times "lubridate", # dates and times
"hms", # times "hms", # times
...@@ -17,7 +20,7 @@ makeLibs <- c("data.table", # data munching ...@@ -17,7 +20,7 @@ makeLibs <- c("data.table", # data munching
dataCleaning::loadLibraries(makeLibs) dataCleaning::loadLibraries(makeLibs)
# Parameters ---- # 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 updateReport <- "yes" # edit this in any way (at all) to get drake to re-load the data
# Some data to play with: # Some data to play with:
...@@ -32,6 +35,7 @@ authors <- "Ben Anderson & Ellis Ridett" ...@@ -32,6 +35,7 @@ authors <- "Ben Anderson & Ellis Ridett"
# Functions ---- # Functions ----
# for use in drake # for use in drake
# the drake book suggests putting this in functions.R but...
addSeason <- function(dt,dateVar,h){ 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 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){ ...@@ -79,7 +83,10 @@ getData <- function(f,updateData){
makeUniq <- function(dt){ makeUniq <- function(dt){
# we suspect there may be duplicates by feeder_ID, dateTime & kW # we suspect there may be duplicates by feeder_ID, dateTime & kW
# remove them (report this in the .Rmd) # 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) return(uniq)
} }
...@@ -150,6 +157,8 @@ makeReport <- function(f,version, type = "html", updateReport){ ...@@ -150,6 +157,8 @@ makeReport <- function(f,version, type = "html", updateReport){
# Set the drake plan ---- # 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( 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! 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 uniqData = makeUniq(origData), # remove duplicates
...@@ -162,4 +171,5 @@ my_plan <- drake::drake_plan( ...@@ -162,4 +171,5 @@ my_plan <- drake::drake_plan(
) )
# see https://books.ropensci.org/drake/projects.html#usage # see https://books.ropensci.org/drake/projects.html#usage
drake_config(my_plan, verbose = 2) # I had expected r_make() to load drake() in the new clean R session but it doesn't
\ No newline at end of file drake::drake_config(my_plan, verbose = 2)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment