From 71169c82d3767f314eabf533f8713df77069d08f Mon Sep 17 00:00:00 2001 From: "Luke W. Johnston" Date: Mon, 22 Apr 2024 00:02:15 +0200 Subject: [PATCH] build: targets to save feedback surveys Closes #25 --- R/save-to-file.R | 6 ++++-- _targets.R | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/R/save-to-file.R b/R/save-to-file.R index 6d555a6..7600370 100644 --- a/R/save-to-file.R +++ b/R/save-to-file.R @@ -37,9 +37,11 @@ save_feedback_to_csv <- function(data, columns) { dplyr::ungroup() |> dplyr::select(data, path) - purrr::walk2( + purrr::map2_chr( data_to_save$data, fs::path_ext_set(data_to_save$path, "csv"), save_to_csv - ) + ) |> + fs::path_rel(usethis::proj_path(".")) |> + as.character() } diff --git a/_targets.R b/_targets.R index 2854fa5..ba1e886 100644 --- a/_targets.R +++ b/_targets.R @@ -87,5 +87,41 @@ list( name = feedback_survey_sessions, command = extract_feedback_sessions(feedback_survey), pattern = map(feedback_survey) + ), + + # Save to file ----------------------------------------------------------- + tar_target( + name = combined_feedback, + command = list( + list( + data = feedback_survey_overall |> + dplyr::mutate(type = "feedback-overall"), + columns = c("course_id", "course_date", "type") + ), + list( + data = feedback_survey_quantitative |> + dplyr::mutate(type = "feedback-quantitative"), + columns = c("course_id", "course_date", "type") + ), + list( + data = feedback_survey_sessions |> + dplyr::mutate(type = "feedback-sessions"), + columns = c("course_id", "course_date", "type", "date") + ), + list( + data = precourse_feedback |> + dplyr::mutate(type = "feedback-precourse"), + columns = c("course_id", "course_date", "type") + ) + ) + ), + tar_target( + name = saved_feedback_sessions_paths, + command = combined_feedback |> + purrr::map(\(feedback) save_feedback_to_csv(feedback$data, feedback$columns)) |> + unlist(), + pattern = map(combined_feedback), + iteration = "list", + format = "file" ) )