Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#library(devtools)
#install_github("ropensci/drake")
library(dplyr)
library(ggplot2)
library(drake)
# Donwload neccesary data
drake_example("main")
# Check if data and report exists
file.exists("main/raw_data.xlsx")
file.exists("main/report.Rmd")
# Crate a custom plot function
create_plot <- function(data) {
ggplot(data, aes(x = Petal.Width, fill = Species)) +
geom_histogram(binwidth = 0.25) +
theme_gray(20)
}
plot_lm <- function(data) {
ggplot(data = data, aes(x = Petal.Width, y = Sepal.Width)) +
geom_point(color='red') +
stat_smooth(method = "lm", col = "red")
}
# Create the plan
plan <- drake_plan(
raw_data = readxl::read_excel(file_in("main/raw_data.xlsx")),
data = raw_data %>%
mutate(Species = forcats::fct_inorder(Species)) %>%
select(-X__1),
hist = create_plot(data),
cor = cor(data$Petal.Width,data$Sepal.Width),
fit = lm(Sepal.Width ~ Petal.Width + Species, data),
plot = plot_lm(data),
report = rmarkdown::render(
knitr_in("main/report.Rmd"),
output_file = file_out("main/report.html"),
quiet = TRUE
)
)
plan
# Excecute the plan
make(plan)
# Interactive graph: hover, zoom, drag, etc.
config <- drake_config(plan)
vis_drake_graph(config)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.