diff --git a/episodes/files/plans/plan_11.R b/episodes/files/plans/plan_11.R index 5c9af52f..fa028596 100644 --- a/episodes/files/plans/plan_11.R +++ b/episodes/files/plans/plan_11.R @@ -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_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) ), # Generate report tar_quarto( penguin_report, path = "penguin_report.qmd", - quiet = FALSE, - packages = c("targets", "tidyverse") + quiet = FALSE ) )