Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
woRkflow
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ben Anderson
woRkflow
Commits
231b0c7b
Commit
231b0c7b
authored
4 years ago
by
Ben Anderson
Browse files
Options
Downloads
Patches
Plain Diff
new _drake_x file called using drake::r_make() in new make_x file
parent
669144c1
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
_drake_basicReport.R
+77
-0
77 additions, 0 deletions
_drake_basicReport.R
make_basicReport.R
+20
-0
20 additions, 0 deletions
make_basicReport.R
with
97 additions
and
0 deletions
_drake_basicReport.R
0 → 100644
+
77
−
0
View file @
231b0c7b
# basic drake makefile
# Libraries ----
library
(
woRkflow
)
# remember to build it first :-)
woRkflow
::
setup
()
# load env.R set up the default paths etc
reqLibs
<-
c
(
"data.table"
,
# data munching
"drake"
,
# what's done stays done
"here"
,
# here
"lubridate"
,
# dates and times
"ggplot2"
,
# plots
"skimr"
# for skim
)
# load them
woRkflow
::
loadLibraries
(
reqLibs
)
# Parameters ----
# Some data to play with:
# https://data.nationalgrideso.com/carbon-intensity1/historic-generation-mix/r/historic_gb_generation_mix
urlToGet
<-
"http://data.nationalgrideso.com/backend/dataset/88313ae5-94e4-4ddc-a790-593554d8c6b9/resource/7b41ea4d-cada-491e-8ad6-7b62f6a63193/download/df_fuel_ckan.csv"
update
<-
"please"
# edit this in any way (at all) to get drake to re-load the data from the url
rmdFile
<-
"basicReport"
# <- name of the .Rmd file to run at the end
title
<-
"UK Electricity Generation"
subtitle
<-
"UK ESO grid data"
authors
<-
"Ben Anderson"
# Functions ----
# for use in drake
getData
<-
function
(
f
,
update
){
# gets the data
message
(
"Getting data from: "
,
f
)
dt
<-
data.table
::
fread
(
f
)
return
(
dt
)
}
makeGWPlot
<-
function
(
dt
){
message
(
"Rebuilding plot"
)
# expects the eso data as a data.table
# draws a plot
dt
[,
rDateTime
:=
lubridate
::
ymd_hms
(
DATETIME
)]
# hurrah, somebody read https://speakerdeck.com/jennybc/how-to-name-files?slide=21
dt
[,
weekDay
:=
lubridate
::
wday
(
rDateTime
,
label
=
TRUE
)]
# draw a megaplot for illustrative purposes
p
<-
ggplot2
::
ggplot
(
dt
,
aes
(
x
=
rDateTime
,
y
=
GENERATION
/
1000
,
colour
=
weekDay
))
+
geom_point
()
+
theme
(
legend.position
=
"bottom"
)
+
labs
(
x
=
"Time"
,
y
=
"Generation (GW - mean per halfhour?)"
,
caption
=
"Source: UK Grid ESO (http://data.nationalgrideso.com)"
)
return
(
p
)
}
makeReport
<-
function
(
f
){
message
(
"Re-running report: "
,
f
)
# default = html
rmarkdown
::
render
(
input
=
paste0
(
here
::
here
(
"Rmd"
,
f
),
".Rmd"
),
# we love here:here() - it helps us find the .Rmd to use
params
=
list
(
title
=
title
,
subtitle
=
subtitle
,
authors
=
authors
),
output_file
=
paste0
(
here
::
here
(
"docs"
,
f
),
".html"
)
# where the output goes
)
}
# Set the drake plan ----
# Clearly this will fail if you do not have internet access...
plan
<-
drake
::
drake_plan
(
esoData
=
getData
(
urlToGet
,
update
),
# returns data as data.table. If you edit 'update' in any way it will reload - drake is watching you!
skimTable
=
skimr
::
skim
(
esoData
),
# create a data description table
gWPlot
=
makeGWPlot
(
esoData
),
# make a plot
out
=
makeReport
(
rmdFile
)
)
drake
::
drake_config
(
plan
,
verbose
=
2
)
This diff is collapsed.
Click to expand it.
make_basicReport.R
0 → 100644
+
20
−
0
View file @
231b0c7b
# make file for drake
# see https://books.ropensci.org/drake/projects.html#usage
# Set up ----
startTime
<-
proc.time
()
# use r_make to run the plan inside a clean R session so nothing gets contaminated
drake
::
r_make
(
source
=
"_drake_basicReport.R"
)
# where we keep the drake plan etc
# we don't keep this in /R because that's where the package functions live
# we don't use "_drake.R" because we have lots of different plans
# Finish off ----
t
<-
proc.time
()
-
startTime
# how long did it take?
elapsed
<-
t
[[
3
]]
print
(
"Done"
)
print
(
paste0
(
"Completed in "
,
round
(
elapsed
/
60
,
3
),
" minutes using "
,
R.version.string
,
" running on "
,
R.version
$
platform
))
\ 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