-
Notifications
You must be signed in to change notification settings - Fork 0
/
_targets.R
71 lines (54 loc) · 1.2 KB
/
_targets.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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Set-up ------------------------------
library(targets)
library(tarchetypes)
# Load packages needed for this project
tar_option_set(
packages = c(
"tidyverse",
"purrr",
"palmerpenguins",
"gtsummary",
"rlang")
)
# Set up a workspace when our code errors
tar_option_set(workspace_on_error = TRUE)
# Load functions to be used in our project
source("R/functions.R")
# Target objects ------------------------------
tar_assign({
file <- tar_target(
"./data/raw_data_2024-08-24.csv",
format = "file")
data <- read_csv(file) |>
tar_target()
# Specify variables of interest for subsequent analyses
xvar <- "body_mass_g" |>
tar_target()
yvar <- "flipper_length_mm" |>
tar_target()
groupvar <- "species" |>
tar_target()
# Tabulate, model, and plot
table <- penguin_table(
data = data,
xvar, yvar, groupvar,
bill_length_mm,
bill_depth_mm,
groupvar = groupvar
) |>
tar_target()
model <- fit_model(
data = data,
xvar = xvar,
yvar = yvar
) |>
tar_target()
plot <- plot_model(
model = model,
data = data,
xvar = xvar,
yvar = yvar,
groupvar = groupvar
) |>
tar_target()
})