Commit bba38b1f authored by B.Anderson's avatar B.Anderson

fixed merge

Merge branch 'master' of git.soton.ac.uk:ba1e12/workflow

Conflicts:
	docs/basicReport.html
parents bf28fd44 9c8efd5b
......@@ -29,6 +29,7 @@ bibliography: '`r here::here("bibliography.bib")`'
---
```{r knitrSetup, include=FALSE}
startTime <- proc.time()
knitr::opts_chunk$set(echo = FALSE) # by default turn off code echo
```
......@@ -56,17 +57,16 @@ There's quite a lot of data...
drake::readd(gWPlot)
```
# Runtime
# R environment
```{r check runtime, include=FALSE}
# within Rmd timing
t <- proc.time() - startTime
elapsed <- t[[3]]
```
Report generated in `r round(elapsed,2)` seconds ( `r round(elapsed/60,2)` minutes) using [knitr](https://cran.r-project.org/package=knitr) in [RStudio](http://www.rstudio.com) with `r R.version.string` running on `r R.version$platform`.
# R environment
## R packages used
* base R [@baseR]
......
# 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.
# 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment