Skip to content

Commit

Permalink
differences for PR #51
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Dec 24, 2024
1 parent 7c55c3b commit 80e05ce
Show file tree
Hide file tree
Showing 18 changed files with 643 additions and 387 deletions.
428 changes: 247 additions & 181 deletions branch.md

Large diffs are not rendered by default.

35 changes: 17 additions & 18 deletions files/plans/plan_10.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,26 @@ tar_plan(
path_to_file("penguins_raw.csv"),
read_csv(!!.x, show_col_types = FALSE)
),
# Clean data
penguins_data = clean_penguin_data(penguins_data_raw),
# Build models
models = list(
combined_model = lm(
bill_depth_mm ~ bill_length_mm, data = penguins_data),
species_model = lm(
bill_depth_mm ~ bill_length_mm + species, data = penguins_data),
interaction_model = lm(
bill_depth_mm ~ bill_length_mm * species, data = penguins_data)
# Clean and group data
tar_group_by(
penguins_data,
clean_penguin_data(penguins_data_raw),
species
),
# Get model summaries
# Get summary of combined model with all species together
combined_summary = model_glance(penguins_data),
# Get summary of one model per species
tar_target(
model_summaries,
glance_with_mod_name_slow(models),
pattern = map(models)
species_summary,
model_glance_slow(penguins_data),
pattern = map(penguins_data)
),
# Get model predictions
# Get predictions of combined model with all species together
combined_predictions = model_glance_slow(penguins_data),
# Get predictions of one model per species
tar_target(
model_predictions,
augment_with_mod_name_slow(models),
pattern = map(models)
species_predictions,
model_augment_slow(penguins_data),
pattern = map(penguins_data)
)
)
38 changes: 18 additions & 20 deletions files/plans/plan_11.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,32 @@ tar_plan(
path_to_file("penguins_raw.csv"),
read_csv(!!.x, show_col_types = FALSE)
),
# Clean data
penguins_data = clean_penguin_data(penguins_data_raw),
# Build models
models = list(
combined_model = lm(
bill_depth_mm ~ bill_length_mm, data = penguins_data),
species_model = lm(
bill_depth_mm ~ bill_length_mm + species, data = penguins_data),
interaction_model = lm(
bill_depth_mm ~ bill_length_mm * species, data = penguins_data)
# Clean and group data
tar_group_by(
penguins_data,
clean_penguin_data(penguins_data_raw),
species
),
# Get model summaries
# Get summary of combined model with all species together
combined_summary = model_glance(penguins_data),
# Get summary of one model per species
tar_target(
model_summaries,
glance_with_mod_name(models),
pattern = map(models)
species_summary,
model_glance(penguins_data),
pattern = map(penguins_data)
),
# Get model predictions
# Get predictions of combined model with all species together
combined_predictions = model_augment(penguins_data),
# Get predictions of one model per species
tar_target(
model_predictions,
augment_with_mod_name(models),
pattern = map(models)
species_predictions,
model_augment(penguins_data),
pattern = map(penguins_data)
),
# Generate report
tar_quarto(
penguin_report,
path = "penguin_report.qmd",
quiet = FALSE,
packages = c("targets", "tidyverse")
quiet = FALSE
)
)
21 changes: 13 additions & 8 deletions files/plans/plan_5.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@ tar_plan(
bill_depth_mm ~ bill_length_mm,
data = penguins_data
),
species_model = lm(
bill_depth_mm ~ bill_length_mm + species,
data = penguins_data
adelie_model = lm(
bill_depth_mm ~ bill_length_mm,
data = filter(penguins_data, species == "Adelie")
),
interaction_model = lm(
bill_depth_mm ~ bill_length_mm * species,
data = penguins_data
chinstrap_model = lm(
bill_depth_mm ~ bill_length_mm,
data = filter(penguins_data, species == "Chinstrap")
),
gentoo_model = lm(
bill_depth_mm ~ bill_length_mm,
data = filter(penguins_data, species == "Gentoo")
),
# Get model summaries
combined_summary = glance(combined_model),
species_summary = glance(species_model),
interaction_summary = glance(interaction_model)
adelie_summary = glance(adelie_model),
chinstrap_summary = glance(chinstrap_model),
gentoo_summary = glance(gentoo_model)
)
23 changes: 11 additions & 12 deletions files/plans/plan_6.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@ tar_plan(
),
# Clean data
penguins_data = clean_penguin_data(penguins_data_raw),
# Build models
models = list(
combined_model = lm(
bill_depth_mm ~ bill_length_mm, data = penguins_data),
species_model = lm(
bill_depth_mm ~ bill_length_mm + species, data = penguins_data),
interaction_model = lm(
bill_depth_mm ~ bill_length_mm * species, data = penguins_data)
# Group data
tar_group_by(
penguins_data_grouped,
penguins_data,
species
),
# Get model summaries
# Build combined model with all species together
combined_summary = model_glance(penguins_data),
# Build one model per species
tar_target(
model_summaries,
glance(models[[1]]),
pattern = map(models)
species_summary,
model_glance(penguins_data_grouped),
pattern = map(penguins_data_grouped)
)
)
28 changes: 28 additions & 0 deletions files/plans/plan_6b.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
options(tidyverse.quiet = TRUE)
source("R/packages.R")
source("R/functions.R")

tar_plan(
# Load raw data
tar_file_read(
penguins_data_raw,
path_to_file("penguins_raw.csv"),
read_csv(!!.x, show_col_types = FALSE)
),
# Clean data
penguins_data = clean_penguin_data(penguins_data_raw),
# Group data
tar_group_by(
penguins_data_grouped,
penguins_data,
species
),
# Build combined model with all species together
combined_summary = model_glance_orig(penguins_data),
# Build one model per species
tar_target(
species_summary,
model_glance_orig(penguins_data_grouped),
pattern = map(penguins_data_grouped)
)
)
34 changes: 34 additions & 0 deletions files/plans/plan_6c.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
options(tidyverse.quiet = TRUE)
source("R/functions.R")
source("R/packages.R")

tar_plan(
# Load raw data
tar_file_read(
penguins_data_raw,
path_to_file("penguins_raw.csv"),
read_csv(!!.x, show_col_types = FALSE)
),
# Clean and group data
tar_group_by(
penguins_data,
clean_penguin_data(penguins_data_raw),
species
),
# Get summary of combined model with all species together
combined_summary = model_glance(penguins_data),
# Get summary of one model per species
tar_target(
species_summary,
model_glance(penguins_data),
pattern = map(penguins_data)
),
# Get predictions of combined model with all species together
combined_predictions = model_glance(penguins_data),
# Get predictions of one model per species
tar_target(
species_predictions,
model_augment(penguins_data),
pattern = map(penguins_data)
)
)
31 changes: 19 additions & 12 deletions files/plans/plan_7.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,26 @@ tar_plan(
),
# Clean data
penguins_data = clean_penguin_data(penguins_data_raw),
# Build models
models = list(
combined_model = lm(
bill_depth_mm ~ bill_length_mm, data = penguins_data),
species_model = lm(
bill_depth_mm ~ bill_length_mm + species, data = penguins_data),
interaction_model = lm(
bill_depth_mm ~ bill_length_mm * species, data = penguins_data)
# Group data
tar_group_by(
penguins_data_grouped,
penguins_data,
species
),
# Get model summaries
# Get summary of combined model with all species together
combined_summary = model_glance(penguins_data),
# Get summary of one model per species
tar_target(
model_summaries,
glance_with_mod_name(models),
pattern = map(models)
species_summary,
model_glance(penguins_data_grouped),
pattern = map(penguins_data_grouped)
),
# Get predictions of combined model with all species together
combined_predictions = model_glance(penguins_data_grouped),
# Get predictions of one model per species
tar_target(
species_predictions,
model_augment(penguins_data_grouped),
pattern = map(penguins_data_grouped)
)
)
35 changes: 17 additions & 18 deletions files/plans/plan_8.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,26 @@ tar_plan(
path_to_file("penguins_raw.csv"),
read_csv(!!.x, show_col_types = FALSE)
),
# Clean data
penguins_data = clean_penguin_data(penguins_data_raw),
# Build models
models = list(
combined_model = lm(
bill_depth_mm ~ bill_length_mm, data = penguins_data),
species_model = lm(
bill_depth_mm ~ bill_length_mm + species, data = penguins_data),
interaction_model = lm(
bill_depth_mm ~ bill_length_mm * species, data = penguins_data)
# Clean and group data
tar_group_by(
penguins_data,
clean_penguin_data(penguins_data_raw),
species
),
# Get model summaries
# Get summary of combined model with all species together
combined_summary = model_glance(penguins_data),
# Get summary of one model per species
tar_target(
model_summaries,
glance_with_mod_name(models),
pattern = map(models)
species_summary,
model_glance(penguins_data),
pattern = map(penguins_data)
),
# Get model predictions
# Get predictions of combined model with all species together
combined_predictions = model_augment(penguins_data),
# Get predictions of one model per species
tar_target(
model_predictions,
augment_with_mod_name(models),
pattern = map(models)
species_predictions,
model_augment(penguins_data),
pattern = map(penguins_data)
)
)
35 changes: 17 additions & 18 deletions files/plans/plan_9.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,26 @@ tar_plan(
path_to_file("penguins_raw.csv"),
read_csv(!!.x, show_col_types = FALSE)
),
# Clean data
penguins_data = clean_penguin_data(penguins_data_raw),
# Build models
models = list(
combined_model = lm(
bill_depth_mm ~ bill_length_mm, data = penguins_data),
species_model = lm(
bill_depth_mm ~ bill_length_mm + species, data = penguins_data),
interaction_model = lm(
bill_depth_mm ~ bill_length_mm * species, data = penguins_data)
# Clean and group data
tar_group_by(
penguins_data,
clean_penguin_data(penguins_data_raw),
species
),
# Get model summaries
# Get summary of combined model with all species together
combined_summary = model_glance(penguins_data),
# Get summary of one model per species
tar_target(
model_summaries,
glance_with_mod_name(models),
pattern = map(models)
species_summary,
model_glance(penguins_data),
pattern = map(penguins_data)
),
# Get model predictions
# Get predictions of combined model with all species together
combined_predictions = model_glance(penguins_data),
# Get predictions of one model per species
tar_target(
model_predictions,
augment_with_mod_name(models),
pattern = map(models)
species_predictions,
model_augment(penguins_data),
pattern = map(penguins_data)
)
)
16 changes: 16 additions & 0 deletions files/tar_functions/model_augment.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
model_augment <- function(penguins_data) {
# Make model
model <- lm(
bill_depth_mm ~ bill_length_mm,
data = penguins_data)
# Get species name
species_name <- unique(penguins_data$species)
# If this is the combined dataset with multiple
# species, changed name to 'combined'
if (length(species_name) > 1) {
species_name <- "combined"
}
# Get model summary and add species name
augment(model) |>
mutate(species = species_name, .before = 1)
}
17 changes: 17 additions & 0 deletions files/tar_functions/model_augment_slow.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
model_augment_slow <- function(penguins_data) {
Sys.sleep(4)
# Make model
model <- lm(
bill_depth_mm ~ bill_length_mm,
data = penguins_data)
# Get species name
species_name <- unique(penguins_data$species)
# If this is the combined dataset with multiple
# species, changed name to 'combined'
if (length(species_name) > 1) {
species_name <- "combined"
}
# Get model summary and add species name
augment(model) |>
mutate(species = species_name, .before = 1)
}
Loading

0 comments on commit 80e05ce

Please sign in to comment.