diff --git a/NAMESPACE b/NAMESPACE index 531e589..bb12a5c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -43,7 +43,7 @@ export(replace_html) export(replace_single_html) export(set_knitr_image_path) export(simple_references) +importFrom(fs,dir_copy) importFrom(magrittr,"%>%") importFrom(readr,write_tsv) importFrom(utils,download.file) -importFrom(utils,unzip) diff --git a/R/coursera.R b/R/coursera.R index 35d5486..3b18bf4 100644 --- a/R/coursera.R +++ b/R/coursera.R @@ -213,6 +213,7 @@ convert_coursera_quizzes <- function(input_quiz_dir = "quizzes", #' @export #' @rdname coursera #' +#' @importFrom utils download.file #' render_coursera <- function( output_dir = file.path("docs", "coursera"), diff --git a/R/example_data.R b/R/example_data.R index 3b663ad..3b33e16 100644 --- a/R/example_data.R +++ b/R/example_data.R @@ -10,6 +10,7 @@ good_quiz_path <- function() { list.files( pattern = "quiz_good.md$", + recursive = TRUE, system.file("extdata", package = "leanbuild"), full.names = TRUE ) @@ -25,6 +26,7 @@ good_quiz_path <- function() { bad_quiz_path <- function() { list.files( pattern = "quiz_bad.md$", + recursive = TRUE, system.file("extdata", package = "leanbuild"), full.names = TRUE ) @@ -35,80 +37,59 @@ bad_quiz_path <- function() { #' @param dest_dir The destination directory you would like the example repo files to be placed. By default is current directory. #' @export #' -#' @importFrom utils download.file -#' @importFrom utils unzip +#' @importFrom fs dir_copy #' @examples +#' # Run this to get the files we need +#' example_files <- leanbuild::example_repo_setup() #' -#' example_repo_setup() example_repo_setup <- function(dest_dir = ".") { - zip_file <- file.path(dest_dir, "example-repo.zip") + bookdown_path <- list.files( + pattern = "_bookdown.yml$", + system.file("extdata/", package = "leanbuild"), + full.names = TRUE + ) + + # Copy over whole directory + fs::dir_copy(dirname(bookdown_path), dest_dir, overwrite = TRUE) - if (!dir.exists(dest_dir)) { - dir.create(dest_dir) - } - download.file(url = "https://github.com/jhudsl/DaSL_Course_Template_Leanpub/raw/main/example-repo.zip", - destfile = zip_file) + copied_files <- list.files(dirname(bookdown_path), full.names = TRUE) - # See what unzip is being used - operating_system <- Sys.info()[1] - message(operating_system) - if (operating_system == "Windows" ){ - # Unzip function doesn't always work for windows - system(paste("7z a -tzip", zip_file, dest_dir)) - } else { - # Unzip the folder - utils::unzip(zip_file, exdir = dest_dir) - } + return(copied_files) } #' Clean up example repo files #' -#' @param dir What directory to delete the example files from +#' @param files_to_remove List of example files to delete. +#' @param verbose TRUE/FALSE would you like progress messages? #' @export #' #' @examples #' -#' example_repo_cleanup() +#' # Run this to get the files we need +#' example_files <- leanbuild::example_repo_setup() #' -example_repo_cleanup <- function(dir = ".") { - - file_list <- file.path(dir, "resources", "needed_leanbuild_files.txt") - if (file.exists(file_list)) { - file_list <- readLines(file.path(dir, "resources", "needed_leanbuild_files.txt")) - } else { - file_list <- NULL - } - # Find example folder file - files_to_remove <- c( - file_list, - "_bookdown.yml", - "_output.yml", - "01-intro.Rmd", - "02-chapter_of_course.Rmd", - "About.Rmd", - "assets", - "docs", - "example-repo.zip", - "index.Rmd", - "quizzes", - "resources", - "Course_Name.rds", - "manuscript", - "question_error_report.tsv", - "packages.bib") - +#' # Run this to delete them +#' example_repo_cleanup(files_to_remove = basename(example_files)) +#' +example_repo_cleanup <- function(files_to_remove, verbose = FALSE) { message("Cleaning up and removing example repo files") - # Now remove it all - lapply(files_to_remove, function(file) { - if (file.exists(file) | dir.exists(file)) { - system(paste0("chmod +w -R", file)) - system(paste0("sudo rm -r ", file)) + files_to_remove <- c(list.files("quizzes", recursive = TRUE, full.names = TRUE), + list.files("docs", recursive = TRUE, full.names = TRUE), + list.files("manuscript", recursive = TRUE, full.names = TRUE), + list.files("resources", recursive = TRUE, full.names = TRUE), + files_to_remove, + "question_error_report.tsv", + "Course_Name.rds" + ) + + lapply(files_to_remove, function(file2remove, verbose = verbose) { + if (file.exists(file2remove)) { + message(paste0("Removing: ", file2remove)) + file.remove(file2remove) } }) -} -# save(bad_quiz, bad_quiz, file = "bad_quiz.RData") -# save(good_quiz, good_quiz, file = "good_quiz.RData") +} diff --git a/inst/extdata/01-intro.Rmd b/inst/extdata/01-intro.Rmd new file mode 100644 index 0000000..6dbc5b9 --- /dev/null +++ b/inst/extdata/01-intro.Rmd @@ -0,0 +1,20 @@ +--- +title: "Course Title" +--- + +```{r, include = FALSE} +leanbuild::set_knitr_image_path() +``` + +# Introduction + +## Motivation +This course will cover + +**Target Audience:** +The course is intended for + +**Curriculum:** +The curriculum will cover + +This course was funded by diff --git a/inst/extdata/02-example-chapter.Rmd b/inst/extdata/02-example-chapter.Rmd new file mode 100644 index 0000000..ff2e72a --- /dev/null +++ b/inst/extdata/02-example-chapter.Rmd @@ -0,0 +1,111 @@ +--- +title: "Example Chapter" +--- + +# Example Chapter + +Every chapter needs to start out with this chunk of code: + +```{r, include = FALSE} +leanbuild::set_knitr_image_path() +``` + +### Code examples + +You can demonstrate code like this: + +```{r} +output_dir <- file.path("resources", "code_output") +if (!dir.exists(output_dir)) { + dir.create(output_dir) +} +``` + +And make plots too: + +```{r} +hist_plot <- hist(iris$Sepal.Length) +``` + +You can also save these plots to file: + +```{r} +png(file.path(output_dir, "test_plot.png")) +hist_plot +dev.off() +``` + +### Image example + + +How to include a Google slide. + +```{r, fig.align='center', echo = FALSE, fig.alt= "Major point!! example image"} +leanbuild::include_slide("https://docs.google.com/presentation/d/1YmwKdIy9BeQ3EShgZhvtb3MgR8P6iDX4DfFD65W_gdQ/edit#slide=id.gcc4fbee202_0_141") +``` + +But if you have the slide or some other image locally downloaded you can also use html like this: + +Major point!! example image + + +### Video examples + +You can use `knitr::include_url()` like this: + +```{r} +knitr::include_url("https://www.youtube.com/embed/VOCYL-FNbr0") +``` + +OR this works: + + + +### Links to files + +This works: + +```{r, fig.align="center", echo=FALSE} +knitr::include_url("https://www.messiah.edu/download/downloads/id/921/Microaggressions_in_the_Classroom.pdf", height = "800px") +``` + +Or this: + +[This works](https://www.messiah.edu/download/downloads/id/921/Microaggressions_in_the_Classroom.pdf). + +Or this: + + + +### Links to websites + +Examples of including a website link. + +This works: + +```{r, fig.align="center"} +knitr::include_url("https://yihui.org") +``` + +OR this: + +![Another link](https://yihui.org) + +OR this: + + + +### Citation examples + +We can put citations at the end of a sentence like this [@R-bookdown]. +Or multiple citations [@R-bookdown, @R-rmarkdown]. + +but they need a ; separator [@R-bookdown, @R-rmarkdown]. + +In text, we can put citations like this @R-rmarkdown. + +## Print out session info + +```{r} +sessionInfo() +``` diff --git a/inst/extdata/_bookdown.yml b/inst/extdata/_bookdown.yml new file mode 100644 index 0000000..cbc3ea3 --- /dev/null +++ b/inst/extdata/_bookdown.yml @@ -0,0 +1,13 @@ +book_filename: "Course_Name" +chapter_name: "Chapter " +repo: https://github.com/jhudsl/DaSL_Course_Template_Bookdown/ +rmd_files: ["index.Rmd", + "01-intro.Rmd", + "02-example-chapter.Rmd"] +new_session: yes +bibliography: "references.bib" +delete_merged_file: true +language: + ui: + chapter_name: "Chapter" +output_dir: "docs" diff --git a/inst/extdata/index.Rmd b/inst/extdata/index.Rmd new file mode 100644 index 0000000..3f3794d --- /dev/null +++ b/inst/extdata/index.Rmd @@ -0,0 +1,6 @@ +--- +date: "`r format(Sys.time(), '%B, %Y')`" +link-citations: yes +--- + +# About this Course diff --git a/inst/extdata/references.bib b/inst/extdata/references.bib new file mode 100644 index 0000000..b501b2a --- /dev/null +++ b/inst/extdata/references.bib @@ -0,0 +1,85 @@ +@Manual{R-base, + title = {R: A Language and Environment for Statistical Computing}, + author = {{R Core Team}}, + organization = {R Foundation for Statistical Computing}, + address = {Vienna, Austria}, + year = {2020}, + url = {https://www.R-project.org/}, +} + +@Manual{R-bookdown, + title = {bookdown: Authoring Books and Technical Documents with R Markdown}, + author = {Yihui Xie}, + year = {2021}, + note = {https://github.com/rstudio/bookdown, +https://pkgs.rstudio.com/bookdown/}, +} + +@Manual{R-knitr, + title = {knitr: A General-Purpose Package for Dynamic Report Generation in R}, + author = {Yihui Xie}, + year = {2021}, + note = {R package version 1.33}, + url = {https://yihui.org/knitr/}, +} + +@Manual{R-rmarkdown, + title = {rmarkdown: Dynamic Documents for R}, + author = {JJ Allaire and Yihui Xie and Jonathan McPherson and Javier Luraschi and Kevin Ushey and Aron Atkins and Hadley Wickham and Joe Cheng and Winston Chang and Richard Iannone}, + year = {2021}, + note = {https://github.com/rstudio/rmarkdown, +https://pkgs.rstudio.com/rmarkdown/}, +} + +@Book{bookdown2016, + title = {bookdown: Authoring Books and Technical Documents with {R} Markdown}, + author = {Yihui Xie}, + publisher = {Chapman and Hall/CRC}, + address = {Boca Raton, Florida}, + year = {2016}, + note = {ISBN 978-1138700109}, + url = {https://bookdown.org/yihui/bookdown}, +} + +@Book{knitr2015, + title = {Dynamic Documents with {R} and knitr}, + author = {Yihui Xie}, + publisher = {Chapman and Hall/CRC}, + address = {Boca Raton, Florida}, + year = {2015}, + edition = {2nd}, + note = {ISBN 978-1498716963}, + url = {https://yihui.org/knitr/}, +} + +@InCollection{knitr2014, + booktitle = {Implementing Reproducible Computational Research}, + editor = {Victoria Stodden and Friedrich Leisch and Roger D. Peng}, + title = {knitr: A Comprehensive Tool for Reproducible Research in {R}}, + author = {Yihui Xie}, + publisher = {Chapman and Hall/CRC}, + year = {2014}, + note = {ISBN 978-1466561595}, + url = {http://www.crcpress.com/product/isbn/9781466561595}, +} + +@Book{rmarkdown2018, + title = {R Markdown: The Definitive Guide}, + author = {Yihui Xie and J.J. Allaire and Garrett Grolemund}, + publisher = {Chapman and Hall/CRC}, + address = {Boca Raton, Florida}, + year = {2018}, + note = {ISBN 9781138359338}, + url = {https://bookdown.org/yihui/rmarkdown}, +} + +@Book{rmarkdown2020, + title = {R Markdown Cookbook}, + author = {Yihui Xie and Christophe Dervieux and Emily Riederer}, + publisher = {Chapman and Hall/CRC}, + address = {Boca Raton, Florida}, + year = {2020}, + note = {ISBN 9780367563837}, + url = {https://bookdown.org/yihui/rmarkdown-cookbook}, +} + diff --git a/man/example_repo_cleanup.Rd b/man/example_repo_cleanup.Rd index daea661..2954265 100644 --- a/man/example_repo_cleanup.Rd +++ b/man/example_repo_cleanup.Rd @@ -4,16 +4,22 @@ \alias{example_repo_cleanup} \title{Clean up example repo files} \usage{ -example_repo_cleanup(dir = ".") +example_repo_cleanup(files_to_remove, verbose = FALSE) } \arguments{ -\item{dir}{What directory to delete the example files from} +\item{files_to_remove}{List of example files to delete.} + +\item{verbose}{TRUE/FALSE would you like progress messages?} } \description{ Clean up example repo files } \examples{ -example_repo_cleanup() +# Run this to get the files we need +example_files <- leanbuild::example_repo_setup() + +# Run this to delete them +example_repo_cleanup(files_to_remove = basename(example_files)) } diff --git a/man/example_repo_setup.Rd b/man/example_repo_setup.Rd index 618f8fa..f5b55bb 100644 --- a/man/example_repo_setup.Rd +++ b/man/example_repo_setup.Rd @@ -13,6 +13,7 @@ example_repo_setup(dest_dir = ".") Set up example repo files } \examples{ +# Run this to get the files we need +example_files <- leanbuild::example_repo_setup() -example_repo_setup() } diff --git a/vignettes/getting-started.Rmd b/vignettes/getting-started.Rmd index 83ae8f4..df28f39 100644 --- a/vignettes/getting-started.Rmd +++ b/vignettes/getting-started.Rmd @@ -68,7 +68,7 @@ But for the purposes of this example we will download a zip file of the files we ```{r} # Run this to get the files we need -leanbuild::example_repo_setup() +example_files <- leanbuild::example_repo_setup() ``` Each of your Rmds needs to have a chunk of code with this at the beginning of the file: @@ -128,6 +128,15 @@ readLines(file.path("manuscript", "Book.txt")) ## Setting up quizzes: +First, we will set up a directory to put our quizzes in. + +```{r} +quiz_dir <- "quizzes" +if(!dir.exists(quiz_dir)) { + dir.create(quiz_dir) +} +``` + By default, leanbuild will look for a folder called `quizzes/` to find your quiz `.md` files. If your quizzes are located somewhere else, you will need to use the `quiz_dir` argument to specify that: @@ -223,7 +232,7 @@ leanbuild::bookdown_to_leanpub(make_book_txt = TRUE, If you don't want those example files hanging around, we can run this function to cleanup the example files. ```{r, echo = FALSE} -leanbuild::example_repo_cleanup() +leanbuild::example_repo_cleanup(files_to_remove = basename(example_files), verbose = FALSE) ``` Lastly, we will print out the session info.