generated from carpentries/workbench-template-rmd
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c55c3b
commit 80e05ce
Showing
18 changed files
with
643 additions
and
387 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.