From 3b22df93d8f18bb660a7bbd4930e9690262cfee6 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Tue, 28 Sep 2021 20:56:40 -0400 Subject: [PATCH] Fix copy_quizzes --- R/bookdown_to_leanpub.R | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/R/bookdown_to_leanpub.R b/R/bookdown_to_leanpub.R index 047cafc..7ed4b93 100644 --- a/R/bookdown_to_leanpub.R +++ b/R/bookdown_to_leanpub.R @@ -146,11 +146,14 @@ copy_bib <- function(path = ".", output_dir = "manuscript") { } } -copy_quizzes <- function(path = "./quizzes", output_dir = "manuscript") { - path <- bookdown_path(path) - files <- list.files(path = path, full.names = TRUE, pattern = "^quiz") +copy_quizzes <- function(quiz_dir = "quizzes", output_dir = "manuscript") { + if (!dir.exists(quiz_dir)) { + stop(paste("The quiz directory specified by quiz_dir:", quiz_dir, "does not exist.")) + } + quizzes <- list.files(path = quiz_dir, full.names = TRUE, pattern = "\\.md$") if (length(files) > 0) { - file.copy(files, file.path(output_dir), overwrite = TRUE) + fs::file_copy(quizzes, file.path(output_dir, basename(quizzes)), + overwrite = TRUE) } } @@ -248,7 +251,7 @@ bookdown_to_leanpub <- function(path = ".", message("Copying bib files") } - copy_quizzes(path, output_dir = output_dir) + copy_quizzes(quiz_dir = quiz_dir, output_dir = output_dir) if (verbose) { message("Copying quiz files") }