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
b0dc4a0
commit b58e076
Showing
8 changed files
with
245 additions
and
183 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
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,16 @@ | ||
model_glance <- 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,16 @@ | ||
model_glance <- 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 | ||
glance(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,6 @@ | ||
model_glance_orig <- function(penguins_data) { | ||
model <- lm( | ||
bill_depth_mm ~ bill_length_mm, | ||
data = penguins_data) | ||
broom::glance(model) | ||
} |
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