-
Notifications
You must be signed in to change notification settings - Fork 0
/
targets-run1.R
24 lines (23 loc) · 839 Bytes
/
targets-run1.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#' @rix r_ver = "4.3.3"
#' @rix r_pkgs = c("targets", "tarchetypes", "curl", "here", "visNetwork", "readr", "dplyr", "ggplot2")
get_data <- function(file) {
read_csv(file, col_types = cols()) %>%
filter(!is.na(Ozone))
}
fit_model <- function(data) {
lm(Ozone ~ Temp, data) %>%
coefficients()
}
plot_model <- function(model, data) {
ggplot(data) +
geom_point(aes(x = Temp, y = Ozone)) +
geom_abline(intercept = model[1], slope = model[2])
}
library(targets)
tar_option_set(packages = c("readr", "dplyr", "ggplot2"))
list(
tarchetypes::tar_download(file, "https://raw.githubusercontent.com/wlandau/targets-four-minutes/refs/heads/main/data.csv", here::here("examples", "targets-run1-data.csv")),
tar_target(data, get_data(file)),
tar_target(model, fit_model(data)),
tar_target(plot, plot_model(model, data))
)