Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
dataCleaning
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SERG
dataCleaning
Commits
d2b03cc4
Commit
d2b03cc4
authored
Jul 9, 2020
by
B.Anderson
Browse files
Options
Downloads
Patches
Plain Diff
removed drake from inside the _drakeXX file
parent
8e8ba05f
No related branches found
No related tags found
2 merge requests
!3
merge a few edits
,
!2
fixed pdf build
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
_drakeCleanFeeders.R
+16
-6
16 additions, 6 deletions
_drakeCleanFeeders.R
with
16 additions
and
6 deletions
_drakeCleanFeeders.R
+
16
−
6
View file @
d2b03cc4
# 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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment