From 3b3bc7af8dcfd859afe34bada7fe56ad91eb68b6 Mon Sep 17 00:00:00 2001 From: John Helveston Date: Wed, 24 Feb 2021 11:36:27 -0500 Subject: [PATCH] major changes to path handling - now can build from html slides on the web --- .Rbuildignore | 1 + DESCRIPTION | 2 +- NEWS.md | 13 ++++ R/all.R | 38 +++++------ R/gif.R | 34 +++++----- R/html.R | 12 ++-- R/pdf.R | 66 ++++++++----------- R/pptx.R | 37 +++++------ R/social.R | 19 ++---- R/thumbnail.R | 30 ++++----- R/utils.R | 139 +++++++++++++++++++++++++++++++--------- README.Rmd | 12 ++-- README.md | 39 +++++------ inst/CITATION | 2 +- man/build_all.Rd | 12 ++-- man/build_gif.Rd | 8 ++- man/build_pdf.Rd | 23 ++++--- man/build_pdf_simple.Rd | 2 +- man/build_pptx.Rd | 9 +-- man/build_thumbnail.Rd | 4 +- 20 files changed, 286 insertions(+), 216 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index bd0b4d0..d6a477f 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -10,3 +10,4 @@ build.R ^\.travis\.yml$ ^CRAN-RELEASE$ +next_release.md diff --git a/DESCRIPTION b/DESCRIPTION index 6a852dc..f9ec010 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: xaringanBuilder Title: Functions For Building Xaringan Slides To Different Outputs -Version: 0.0.4.9000 +Version: 0.0.5.9000 Authors@R: c(person(given = "John", family = "Helveston", diff --git a/NEWS.md b/NEWS.md index 6a46869..6cac36d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,16 @@ +# xaringanBuilder 0.0.5 + +## Summary of larger updates: + +* Major improvements to how paths are handled by adding the build_paths() function (not exported). Now you can use a url to build to any output types except for social and html (which both require starting from the Rmd file). +* Added build_to_pdf() function (not exported) as an internal helper to build from a Rmd or html file to the pdf. + +## Summary of smaller updates: + +* Added `assert_chrome_installed()` for issue #12 + +## Bugs + # xaringanBuilder 0.0.4 * Added `build_social()` for making a png of the first slides sized for sharing on social media. diff --git a/R/all.R b/R/all.R index 691449d..ec1e8ce 100644 --- a/R/all.R +++ b/R/all.R @@ -1,15 +1,15 @@ #' Build xaringan slides to multiple outputs. #' #' Build xaringan slides to multiple outputs. Options are `"html"`, `"pdf"`, -#' `"gif"`, `"pptx"`, `"thumbnail"`, and `"social"`. +#' `"gif"`, `"pptx"`, `"thumbnail"`, and `"social"`. See individual +#' build_..() functions for details about each output type. #' @param input Path to Rmd file of xaringan slides. #' @param include A vector of the different output types to build. Options are -#' `"html"`, `"pdf"`, `"gif"`, `"pptx"`, and `"thumbnail"` (a png image of the -#' first slide). Defaults to `c("html", "pdf", "gif", "pptx", "thumbnail")`. +#' `"html"`, `"pdf"`, `"gif"`, `"pptx"`, `"thumbnail"`, and `"social"`. +#' Defaults to `c("html", "pdf", "gif", "pptx", "thumbnail", "social")`. #' @param exclude A vector of the different output types to NOT build. Options -#' are `"html"`, `"pdf"`, `"gif"`, `"pptx"`, and `"thumbnail"` (a png image of -#' the first slide). Defaults to `NULL`, in which case all all output types -#' are rendered. +#' are `"html"`, `"pdf"`, `"gif"`, `"pptx"`, `"thumbnail"`, and `"social"`. +#' Defaults to `NULL`, in which case all all output types are built. #' @param complex_slides For "complex" slides (e.g. slides with panelsets or #' other html widgets or advanced features), set `complex_slides = TRUE`. #' Defaults to `FALSE`. This will use the {chromote} package to iterate through @@ -41,10 +41,11 @@ build_all <- function( partial_slides = FALSE, delay = 1 ) { + # Check that input file has the correct extension assert_path_ext(input, "rmd") - input <- fs::path_abs(input) - input_html <- fs::path_ext_set(input, "html") - input_pdf <- fs::path_ext_set(input, "pdf") + + # Build input and output paths + paths <- build_paths(input, output_file = NULL) include <- match.arg(include, several.ok = TRUE) do_htm <- ("html" %in% include) && (! "html" %in% exclude) @@ -74,35 +75,36 @@ build_all <- function( # if at some point intermediate files are removed if not requested, the # logic here will need to be changed. - if (do_gif && (!fs::file_exists(input_pdf) || do_htm)) { + if (do_gif && (!fs::file_exists(paths$input$pdf) || do_htm)) { # to make a gif we need the PDF file # or if we update the HTML, we should also update the PDF for the gif do_pdf <- TRUE } - if (do_ppt && (!fs::file_exists(input_pdf) || do_htm)) { + if (do_ppt && (!fs::file_exists(paths$input$pdf) || do_htm)) { # to make a pptx we need the PDF file # or if we update the HTML, we should also update the PDF for the pptx do_pdf <- TRUE } - if ((do_pdf || do_thm) && !fs::file_exists(input_html)) { + if ((do_pdf || do_thm) && !fs::file_exists(paths$input$html)) { # to make a PDF or thumbnail we need the html file do_htm <- TRUE } # Do each step in order to ensure updates propagate # (or we use the current version of the required build step) - if (do_soc) build_html(input) - if (do_htm) build_html(input) - if (do_thm) build_thumbnail(input_html) + if (do_soc) build_social(paths$input$rmd, paths$output$social) + if (do_htm) build_html(paths$input$rmd, paths$output$html) + if (do_thm) build_thumbnail(paths$input$html, paths$output$thumbnail) if (do_pdf) { build_pdf( - input = input_html, + input = paths$input$html, + output_file = paths$output$pdf, complex_slides = complex_slides, partial_slides = partial_slides, delay = delay) } - if (do_gif) build_gif(input_pdf) - if (do_ppt) build_pptx(input_pdf) + if (do_gif) build_gif(paths$input$pdf, paths$output$gif) + if (do_ppt) build_pptx(paths$input$pdf, paths$output$pptx) invisible(input) } diff --git a/R/gif.R b/R/gif.R index 177c231..a6a8c5d 100644 --- a/R/gif.R +++ b/R/gif.R @@ -1,8 +1,10 @@ #' Build xaringan slides as gif file. #' -#' Build xaringan slides as a gif file from a Rmd, html, or pdf file. The -#' function builds to the pdf and then converts it to a gif. -#' @param input Path to Rmd, html, or pdf file of xaringan slides. +#' Build xaringan slides as a gif file. The function builds to the pdf and +#' then converts it to a gif. +#' @param input Path to a Rmd, html, or pdf file, or a url of xaringan slides. +#' If the input is a url to xaringan slides on a website, you must provide the +#' full url ending in ".html". #' @param output_file Name of the output gif file. #' @param density Resolution of the resulting gif file. #' @param fps Frames per second of the resulting gif file. @@ -33,28 +35,22 @@ build_gif <- function( complex_slides = FALSE, partial_slides = FALSE, delay = 1 - ) { +) { # Check input and output files have correct extensions - assert_path_ext(input, c("rmd", "html", "pdf"), arg = "input") - output_file <- check_output_file(input, output_file, "gif") + assert_io_paths(input, c("rmd", "html", "pdf"), output_file, "gif") - # Create full file paths from root - input <- fs::path_abs(input) - output_file <- fs::path_abs(output_file) + # Build input and output paths + paths <- build_paths(input, output_file) - # Build - if (test_path_ext(input, c("rmd", "html"))) { - build_pdf( - input = input, - output_file = fs::path_ext_set(output_file, "pdf"), - complex_slides = complex_slides, - partial_slides = partial_slides, - delay = delay) - input <- fs::path_ext_set(input, "pdf") + # Build html and / or pdf (if input is not pdf) + if (!test_path_ext(input, "pdf")) { + build_to_pdf(input, paths, complex_slides, partial_slides, delay) } + # Build gif from pdf + input <- paths$input$pdf + output_file <- paths$output$gif print_build_status(input, output_file) - pngs <- pdf_to_pngs(input, density) pngs_joined <- magick::image_join(pngs) pngs_animated <- magick::image_animate(pngs_joined, fps = fps) diff --git a/R/html.R b/R/html.R index 42da1d5..8e33638 100644 --- a/R/html.R +++ b/R/html.R @@ -14,14 +14,14 @@ #' } build_html <- function(input, output_file = NULL) { # Check input and output files have correct extensions - assert_path_ext(input, "rmd", arg = "input") - output_file <- check_output_file(input, output_file, "html") + assert_io_paths(input, "rmd", output_file, "html") - # Create full file paths from root - input <- fs::path_abs(input) - output_file <- fs::path_abs(output_file) + # Build input and output paths + paths <- build_paths(input, output_file) + input <- paths$input$rmd + output_file <- paths$output$html - # Build + # Build html from rmd print_build_status(input, output_file) rmarkdown::render( input = input, diff --git a/R/pdf.R b/R/pdf.R index fe3ed50..e2aa344 100644 --- a/R/pdf.R +++ b/R/pdf.R @@ -1,10 +1,11 @@ #' Build xaringan slides as pdf file. #' -#' Build xaringan slides to a pdf file. Requires a local installation of +#' Build xaringan slides as a pdf file. Requires a local installation of #' Chrome. If you set `complex_slides = TRUE` or `partial_slides = TRUE`, -#' you will also need to install the {chromote} package: -#' `devtools::install_github("rstudio/chromote")` -#' @param input Path to Rmd or html file of xaringan slides. +#' you will also need to install the {chromote} and {pdftools} packages. +#' @param input Path to a Rmd file or html file / url of xaringan slides. If +#' the input is a url to xaringan slides on a website, you must provide the +#' full url ending in ".html". #' @param output_file The name of the output file. If `NULL` (the default) then #' the output filename will be based on filename for the input file. #' If a filename is provided, a path to the output file can also be provided. @@ -22,21 +23,23 @@ #' @export #' @examples #' \dontrun{ -#' # Build simple pdf from Rmd or html file +#' # Build a pdf from a Rmd or html file #' build_pdf("slides.Rmd") #' build_pdf("slides.html") #' -#' # Build simple pdf from Rmd or html file and include -#' # partial (continuation) slides +#' # Build a pdf from a url +#' build_pdf("http://www.mysite.com/myslides.html") +#' +#' # Build a pdf with partial (continuation) slides #' build_pdf("slides.Rmd", partial_slides = TRUE) #' build_pdf("slides.html", partial_slides = TRUE) #' -#' # Build "complex" xaringan slides to pdf from Rmd or html file +#' # Build a pdf of "complex" xaringan slides #' build_pdf("slides_complex.Rmd", complex_slides = TRUE) #' build_pdf("slides_complex.html", complex_slides = TRUE) #' -#' # Build "complex" xaringan slides to pdf from Rmd or html file and include -#' # partial (continuation) slides +#' # Build a pdf of "complex" xaringan slides and include partial +#' # (continuation) slides #' build_pdf(input = "slides_complex.Rmd", #' output_file = "slides_complex_partial.pdf", #' complex_slides = TRUE, @@ -57,26 +60,24 @@ build_pdf <- function( assert_chrome_installed() # Check input and output files have correct extensions - assert_path_ext(input, c("rmd", "html"), arg = "input") - output_file <- check_output_file(input, output_file, "pdf") + assert_io_paths(input, c("rmd", "html"), output_file, "pdf") - # Create full file paths from root - input <- fs::path_abs(input) - output_file <- fs::path_abs(output_file) + # Build input and output paths + paths <- build_paths(input, output_file) - # Build + # Build html (if input is rmd) if (test_path_ext(input, "rmd")) { - build_html( - input = input, - output_file = fs::path_ext_set(output_file, "html") - ) - input <- fs::path_ext_set(input, "html") + build_html(paths$input$rmd, paths$output$html) } + # Build pdf from html + output_file <- paths$output$pdf if (complex_slides | partial_slides) { - build_pdf_complex(input, output_file, partial_slides, delay) + build_pdf_complex(paths$input$url, output_file, partial_slides, delay) } else { - build_pdf_simple(input, output_file) + input <- paths$input$html + if (is_url(input)) { input <- paths$input$url } + build_pdf_simple(input, output_file) } } @@ -89,7 +90,7 @@ build_pdf <- function( #' @param output_file The name of the output file. If `NULL` (the default) then #' the output filename will be based on filename for the input file. #' If a filename is provided, a path to the output file can also be provided. -build_pdf_simple <- function(input, output_file) { +build_pdf_simple <- function(input, output_file = NULL) { print_build_status(input, output_file) pagedown::chrome_print( input = input, @@ -123,23 +124,6 @@ build_pdf_complex <- function(input, output_file, partial_slides, delay) { stop("`pdftools` is required: install.packages('pdftools')") } - is_url <- grepl("^(ht|f)tp", tolower(input)) - - if (is.null(output_file)) { - if (is_url) { - output_file <- fs::path_ext_set(fs::path_file(input), "pdf") - } else { - output_file <- fs::path_ext_set(input, "pdf") - } - } - - if (!is_url && !grepl("^file://", input)) { - if (!tolower(fs::path_ext(input)) %in% c("htm", "html")) { - stop("`input` must be the HTML version of the slides.") - } - input <- paste0("file://", fs::path_abs(input)) - } - b <- chromote::ChromoteSession$new() on.exit(b$close(), add = TRUE) diff --git a/R/pptx.R b/R/pptx.R index 9d4ac6b..e3111bf 100644 --- a/R/pptx.R +++ b/R/pptx.R @@ -1,9 +1,10 @@ #' Build xaringan slides as pptx file. #' -#' Build xaringan slides as pptx file from a Rmd, html, or pdf file. The -#' function builds to the pdf and then inserts a png image of each slide -#' as a new slide in a pptx file. -#' @param input Path to Rmd, html, or pdf file of xaringan slides. +#' Build xaringan slides as a pptx file. The function builds to the pdf and +#' then inserts a png image of each slide as a new slide in a pptx file. +#' @param input Path to a Rmd, html, or pdf file, or a url of xaringan slides. +#' If the input is a url to xaringan slides on a website, you must provide the +#' full url ending in ".html". #' @param output_file Name of the output pptx file. #' @param density Resolution of the resulting pptx file. #' @param complex_slides For "complex" slides (e.g. slides with panelsets or @@ -32,33 +33,27 @@ build_pptx <- function( complex_slides = FALSE, partial_slides = FALSE, delay = 1 - ) { +) { if (!requireNamespace("officer", quietly = TRUE)) { stop("`officer` is required: install.packages('officer')") } + # Check input and output files have correct extensions - assert_path_ext(input, c("rmd", "html", "pdf"), arg = "input") - output_file <- check_output_file(input, output_file, "pptx") + assert_io_paths(input, c("rmd", "html", "pdf"), output_file, "pptx") - # Create full file paths from root - input <- fs::path_abs(input) - output_file <- fs::path_abs(output_file) + # Build input and output paths + paths <- build_paths(input, output_file) - # Build - if (test_path_ext(input, c("rmd", "html"))) { - build_pdf( - input = input, - output_file = fs::path_ext_set(output_file, "pdf"), - complex_slides = complex_slides, - partial_slides = partial_slides, - delay = delay) - input <- fs::path_ext_set(input, "pdf") + # Build html and / or pdf (if input is not pdf) + if (!test_path_ext(input, "pdf")) { + build_to_pdf(input, paths, complex_slides, partial_slides, delay) } + # Build pptx from pdf + input <- paths$input$pdf + output_file <- paths$output$pptx print_build_status(input, output_file) - pngs <- pdf_to_pngs(input, density) - doc <- officer::read_pptx() for (i in 1:length(pngs)) { png_path <- magick::image_write( diff --git a/R/social.R b/R/social.R index 6d73ad3..fd036b3 100644 --- a/R/social.R +++ b/R/social.R @@ -30,22 +30,15 @@ build_social <- function(input, output_file = NULL) { assert_chrome_installed() # Check input and output files have correct extensions - assert_path_ext(input, "rmd", arg = "input") - output_null <- is.null(output_file) - output_file <- check_output_file(input, output_file, "png") + assert_io_paths(input, "rmd", output_file, "png") - # Create full file paths from root - input <- fs::path_abs(input) - output_file <- fs::path_abs(output_file) + # Build input and output paths + paths <- build_paths(input, output_file) + input <- paths$input$rmd + output_file <- paths$output$social - # Append "_social" to output_file name if not provided by user - if (output_null) { - output_file <- append_to_file_path(output_file, "_social") - } - - # Build + # Build png from rmd print_build_status(input, output_file) - webshot2::rmdshot( doc = input, file = output_file, diff --git a/R/thumbnail.R b/R/thumbnail.R index dd80dae..0810a36 100644 --- a/R/thumbnail.R +++ b/R/thumbnail.R @@ -2,7 +2,9 @@ #' #' Build png thumbnail image of first xaringan slide. Requires a local #' installation of Chrome. -#' @param input Path to Rmd or html file of xaringan slides. +#' @param input Path to a Rmd file or html file / url of xaringan slides. If +#' the input is a url to xaringan slides on a website, you must provide the +#' full url ending in ".html". #' @param output_file Name of the output png file. #' @export #' @examples @@ -17,30 +19,20 @@ build_thumbnail <- function(input, output_file = NULL) { assert_chrome_installed() # Check input and output files have correct extensions - assert_path_ext(input, c("rmd", "html"), arg = "input") - output_null <- is.null(output_file) - output_file <- check_output_file(input, output_file, "png") + assert_io_paths(input, c("rmd", "html"), output_file, "png") - # Create full file paths from root - input <- fs::path_abs(input) - output_file <- fs::path_abs(output_file) + # Build input and output paths + paths <- build_paths(input, output_file) - # Build + # Build html (if input is rmd) if (test_path_ext(input, "rmd")) { - build_html( - input = input, - output_file = fs::path_ext_set(output_file, "html") - ) - input <- fs::path_ext_set(input, "html") - } - - # Append "_thumbnail" to output_file name if not provided by user - if (output_null) { - output_file <- append_to_file_path(output_file, "_thumbnail") + build_html(paths$input$rmd, paths$output$html) } + # Build png from html + input <- paths$input$html + output_file <- paths$output$thumbnail print_build_status(input, output_file) - pagedown::chrome_print( input = input, output = output_file, diff --git a/R/utils.R b/R/utils.R index fd6e17f..88823d4 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,33 +1,95 @@ -print_build_status <- function(input, output_file) { - cli::cli_process_start( - "Building {.file {fs::path_file(output_file)}} from {.path {fs::path_file(input)}}", - on_exit = "done" - ) +assert_io_paths <- function(input, input_ext, output_file, output_file_ext) { + assert_path_ext(input, input_ext, arg = "input") + if (!is.null(output_file)) { + assert_path_ext(output_file, output_file_ext, arg = "output_file") + } } -pdf_to_pngs <- function(input, density) { - pdf <- magick::image_read(input, density = density) - pngs <- magick::image_convert(pdf, 'png') - return(pngs) +assert_path_ext <- function(path, expected_ext, arg) { + if (!test_path_ext(path, expected_ext)) { + expected_ext <- paste0(".", expected_ext, collapse = ", ") + stop("`", arg, "` must have extension: ", expected_ext, call. = FALSE) + } } test_path_ext <- function(path, expected_ext) { - tolower(fs::path_ext(path)) %in% expected_ext + return(tolower(fs::path_ext(path)) %in% expected_ext) } -assert_path_ext <- function(path, expected_ext, arg) { - if (!test_path_ext(path, expected_ext)) { - expected_ext <- paste0(".", expected_ext, collapse = ", ") - stop("`", arg, "` must have extension: ", expected_ext, call. = FALSE) +assert_chrome_installed <- function() { + chromePath <- NULL + error <- paste0( + "This function requires a local installation of the Chrome ", + "browser. You can also use other browsers based on Chromium, ", + "such as Chromium itself, Edge, Vivaldi, Brave, or Opera.") + tryCatch({ + chromePath <- chromote::find_chrome() + }, + error = function(e) { message(error) } + ) + if (is.null(chromePath)) { + stop(error) } } -check_output_file <- function(input, output_file, ext) { +build_paths <- function(input, output_file = NULL) { + # Build input paths + if (is_url(input)) { + input_root <- fs::path_abs(fs::path_file(input)) + input_html <- input + input_url <- input + } else { + input_root <- fs::path_abs(input) + input_html <- fs::path_ext_set(input_root, "html") + input_url <- paste0("file://", input_html) + } + input_rmd <- fs::path_ext_set(input_root, "rmd") + input_pdf <- fs::path_ext_set(input_root, "pdf") + + # Build output_file paths + if (is.null(output_file)) { + if (is_url(input)) { + output_root <- fs::path_abs(fs::path_file(input)) + } else { + output_root <- fs::path_abs(input) + } + } else { + output_root <- fs::path_abs(output_file) + } + output_html <- fs::path_ext_set(output_root, "html") + output_pdf <- fs::path_ext_set(output_root, "pdf") + output_gif <- fs::path_ext_set(output_root, "gif") + output_pptx <- fs::path_ext_set(output_root, "pptx") + output_png <- fs::path_ext_set(output_root, "png") + output_thumbnail <- output_png + output_social <- output_png + # Append "_thumbnail" and "_social" to png outputs if (is.null(output_file)) { - return(fs::path_ext_set(input, ext)) + output_thumbnail <- append_to_file_path(output_png, "_thumbnail") + output_social <- append_to_file_path(output_png, "_social") } - assert_path_ext(output_file, ext, arg = "output_file") - return(output_file) + + # Return path list + return(list( + input = list( + url = input_url, + html = input_html, + rmd = input_rmd, + pdf = input_pdf + ), + output = list( + html = output_html, + pdf = output_pdf, + gif = output_gif, + pptx = output_pptx, + thumbnail = output_thumbnail, + social = output_social + ) + )) +} + +is_url <- function(input) { + return(grepl("^(ht|f)tp", tolower(input))) } append_to_file_path <- function(path, s) { @@ -43,18 +105,35 @@ append_to_file_path <- function(path, s) { ) } -assert_chrome_installed <- function() { - chromePath <- NULL - error <- paste0( - "This function requires a local installation of the Chrome ", - "browser. You can also use other browsers based on Chromium, ", - "such as Chromium itself, Edge, Vivaldi, Brave, or Opera.") - tryCatch({ - chromePath <- chromote::find_chrome() - }, - error = function(e) { message(error) } +pdf_to_pngs <- function(input, density) { + pdf <- magick::image_read(input, density = density) + pngs <- magick::image_convert(pdf, 'png') + return(pngs) +} + +print_build_status <- function(input, output_file) { + cli::cli_process_start( + "Building {.file {fs::path_file(output_file)}} from {.path {fs::path_file(input)}}", + on_exit = "done" ) - if (is.null(chromePath)) { - stop(error) +} + +build_to_pdf <- function( + input, + paths, + complex_slides, + partial_slides, + delay +) { + if (test_path_ext(input, "rmd")) { + build_pdf( + input = paths$input$rmd, + output_file = paths$output$pdf, + complex_slides, partial_slides, delay) + } else if (test_path_ext(input, "html")) { + build_pdf( + input = input, + output_file = paths$output$pdf, + complex_slides, partial_slides, delay) } } diff --git a/README.Rmd b/README.Rmd index 65639e9..df94608 100644 --- a/README.Rmd +++ b/README.Rmd @@ -61,21 +61,23 @@ build_html("slides.Rmd") ### Build PDF -Build a pdf file from a Rmd or html file: +Build a pdf file from a Rmd or html file, or a url to slides: ``` build_pdf("slides.Rmd") build_pdf("slides.html") +build_pdf("http://www.mysite.com/myslides.html") ``` ### Build GIF -Build a gif file from a Rmd, html, or pdf file: +Build a gif file from a Rmd, html, or pdf file, or a url to slides: ``` build_gif("slides.Rmd") build_gif("slides.html") build_gif("slides.pdf") +build_gif("http://www.mysite.com/myslides.html") ``` Example: @@ -84,23 +86,25 @@ Example: ### Build PPTX -Build a pptx file from a Rmd, html or pdf file (pptx contains slides of png images of each rendered xaringan slide): +Build a pptx file from a Rmd, html or pdf file, or a url to slides. The pptx file contains slides of png images of each rendered xaringan slide: ``` build_pptx("slides.Rmd") build_pptx("slides.html") build_pptx("slides.pdf") +build_pptx("http://www.mysite.com/myslides.html") ``` (See the [slidex](https://github.com/datalorax/slidex) package by @datalorax to do the opposite: pptx --> xaringan!) ### Build Thumbnail -Build a "thumbnail" png image of the first slide from a Rmd or html file (useful for Youtube thumbnail): +Build a "thumbnail" png image of the first slide from a Rmd or html file, or a url to slides (useful for Youtube thumbnail): ``` build_thumbnail("slides.Rmd") build_thumbnail("slides.html") +build_thumbnail("http://www.mysite.com/myslides.html") ``` Example: diff --git a/README.md b/README.md index 8f4148f..ed6ae21 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ - [![Lifecycle: @@ -13,12 +12,12 @@ status](https://travis-ci.com/jhelvy/xaringanBuilder.svg?branch=master)](https:/ Build xaringan slides to multiple output formats: - - html - - pdf - - gif - - pptx - - thumbnail - png of first slide (useful for Youtube thumbnail) - - social - png of first slide sized for social media sharing +- html +- pdf +- gif +- pptx +- thumbnail - png of first slide (useful for Youtube thumbnail) +- social - png of first slide sized for social media sharing (e.g. Twitter) ## Installation @@ -43,18 +42,20 @@ Build an html file from a Rmd file: ### Build PDF -Build a pdf file from a Rmd or html file: +Build a pdf file from a Rmd or html file, or a url to slides: build_pdf("slides.Rmd") build_pdf("slides.html") + build_pdf("http://www.mysite.com/myslides.html") ### Build GIF -Build a gif file from a Rmd, html, or pdf file: +Build a gif file from a Rmd, html, or pdf file, or a url to slides: build_gif("slides.Rmd") build_gif("slides.html") build_gif("slides.pdf") + build_gif("http://www.mysite.com/myslides.html") Example: @@ -62,23 +63,25 @@ Example: ### Build PPTX -Build a pptx file from a Rmd, html or pdf file (pptx contains slides of -png images of each rendered xaringan slide): +Build a pptx file from a Rmd, html or pdf file, or a url to slides. The +pptx file contains slides of png images of each rendered xaringan slide: build_pptx("slides.Rmd") build_pptx("slides.html") build_pptx("slides.pdf") + build_pptx("http://www.mysite.com/myslides.html") (See the [slidex](https://github.com/datalorax/slidex) package by -@datalorax to do the opposite: pptx –\> xaringan\!) +@datalorax to do the opposite: pptx –> xaringan!) ### Build Thumbnail -Build a “thumbnail” png image of the first slide from a Rmd or html file -(useful for Youtube thumbnail): +Build a “thumbnail” png image of the first slide from a Rmd or html +file, or a url to slides (useful for Youtube thumbnail): build_thumbnail("slides.Rmd") build_thumbnail("slides.html") + build_thumbnail("http://www.mysite.com/myslides.html") Example: @@ -178,11 +181,11 @@ For example, to build a pptx from a Rmd file without Chrome, you could: ## Author, Version, and License Information - - Author: *John Paul Helveston* +- Author: *John Paul Helveston* [www.jhelvy.com](http://www.jhelvy.com/) - - Date First Written: *September 27, 2020* - - Most Recent Update: February 14 2021 - - License: +- Date First Written: *September 27, 2020* +- Most Recent Update: February 24 2021 +- License: [MIT](https://github.com/jhelvy/xaringanBuilder/blob/master/LICENSE.md) ## Citation Information diff --git a/inst/CITATION b/inst/CITATION index 9150921..7f67b1d 100644 --- a/inst/CITATION +++ b/inst/CITATION @@ -5,7 +5,7 @@ citEntry( title = "xaringanBuilder: Functions for building xaringan slides to different outputs.", author = "John Paul Helveston", year = "2021", - note = "R package version 0.0.4", + note = "R package version 0.0.5", url = "https://jhelvy.github.io/xaringanBuilder/", textVersion = "John Paul Helveston (2021). xaringanBuilder: Functions for building xaringan slides to different outputs." ) diff --git a/man/build_all.Rd b/man/build_all.Rd index b6adb70..b358c75 100644 --- a/man/build_all.Rd +++ b/man/build_all.Rd @@ -17,13 +17,12 @@ build_all( \item{input}{Path to Rmd file of xaringan slides.} \item{include}{A vector of the different output types to build. Options are -`"html"`, `"pdf"`, `"gif"`, `"pptx"`, and `"thumbnail"` (a png image of the -first slide). Defaults to `c("html", "pdf", "gif", "pptx", "thumbnail")`.} +`"html"`, `"pdf"`, `"gif"`, `"pptx"`, `"thumbnail"`, and `"social"`. +Defaults to `c("html", "pdf", "gif", "pptx", "thumbnail", "social")`.} \item{exclude}{A vector of the different output types to NOT build. Options -are `"html"`, `"pdf"`, `"gif"`, `"pptx"`, and `"thumbnail"` (a png image of -the first slide). Defaults to `NULL`, in which case all all output types -are rendered.} +are `"html"`, `"pdf"`, `"gif"`, `"pptx"`, `"thumbnail"`, and `"social"`. +Defaults to `NULL`, in which case all all output types are built.} \item{complex_slides}{For "complex" slides (e.g. slides with panelsets or other html widgets or advanced features), set `complex_slides = TRUE`. @@ -41,7 +40,8 @@ TRUE`.} } \description{ Build xaringan slides to multiple outputs. Options are `"html"`, `"pdf"`, -`"gif"`, `"pptx"`, `"thumbnail"`, and `"social"`. +`"gif"`, `"pptx"`, `"thumbnail"`, and `"social"`. See individual +build_..() functions for details about each output type. } \examples{ \dontrun{ diff --git a/man/build_gif.Rd b/man/build_gif.Rd index c95a06e..8823738 100644 --- a/man/build_gif.Rd +++ b/man/build_gif.Rd @@ -15,7 +15,9 @@ build_gif( ) } \arguments{ -\item{input}{Path to Rmd, html, or pdf file of xaringan slides.} +\item{input}{Path to a Rmd, html, or pdf file, or a url of xaringan slides. +If the input is a url to xaringan slides on a website, you must provide the +full url ending in ".html".} \item{output_file}{Name of the output gif file.} @@ -38,8 +40,8 @@ a new slide. Only used if `complex_slides = TRUE` or `partial_slides = TRUE`.} } \description{ -Build xaringan slides as a gif file from a Rmd, html, or pdf file. The -function builds to the pdf and then converts it to a gif. +Build xaringan slides as a gif file. The function builds to the pdf and +then converts it to a gif. } \examples{ \dontrun{ diff --git a/man/build_pdf.Rd b/man/build_pdf.Rd index e8310b7..6114142 100644 --- a/man/build_pdf.Rd +++ b/man/build_pdf.Rd @@ -13,7 +13,9 @@ build_pdf( ) } \arguments{ -\item{input}{Path to Rmd or html file of xaringan slides.} +\item{input}{Path to a Rmd file or html file / url of xaringan slides. If +the input is a url to xaringan slides on a website, you must provide the +full url ending in ".html".} \item{output_file}{The name of the output file. If `NULL` (the default) then the output filename will be based on filename for the input file. @@ -34,28 +36,29 @@ a new slide. Only used if `complex_slides = TRUE` or `partial_slides = TRUE`.} } \description{ -Build xaringan slides to a pdf file. Requires a local installation of +Build xaringan slides as a pdf file. Requires a local installation of Chrome. If you set `complex_slides = TRUE` or `partial_slides = TRUE`, -you will also need to install the {chromote} package: -`devtools::install_github("rstudio/chromote")` +you will also need to install the {chromote} and {pdftools} packages. } \examples{ \dontrun{ -# Build simple pdf from Rmd or html file +# Build a pdf from a Rmd or html file build_pdf("slides.Rmd") build_pdf("slides.html") -# Build simple pdf from Rmd or html file and include -# partial (continuation) slides +# Build a pdf from a url +build_pdf("http://www.mysite.com/myslides.html") + +# Build a pdf with partial (continuation) slides build_pdf("slides.Rmd", partial_slides = TRUE) build_pdf("slides.html", partial_slides = TRUE) -# Build "complex" xaringan slides to pdf from Rmd or html file +# Build a pdf of "complex" xaringan slides build_pdf("slides_complex.Rmd", complex_slides = TRUE) build_pdf("slides_complex.html", complex_slides = TRUE) -# Build "complex" xaringan slides to pdf from Rmd or html file and include -# partial (continuation) slides +# Build a pdf of "complex" xaringan slides and include partial +# (continuation) slides build_pdf(input = "slides_complex.Rmd", output_file = "slides_complex_partial.pdf", complex_slides = TRUE, diff --git a/man/build_pdf_simple.Rd b/man/build_pdf_simple.Rd index 6878bdc..d62c559 100644 --- a/man/build_pdf_simple.Rd +++ b/man/build_pdf_simple.Rd @@ -4,7 +4,7 @@ \alias{build_pdf_simple} \title{Print "simple" xaringan slides to PDF} \usage{ -build_pdf_simple(input, output_file) +build_pdf_simple(input, output_file = NULL) } \arguments{ \item{input}{Path to Rmd or html file of xaringan slides.} diff --git a/man/build_pptx.Rd b/man/build_pptx.Rd index b32c68c..914e16f 100644 --- a/man/build_pptx.Rd +++ b/man/build_pptx.Rd @@ -14,7 +14,9 @@ build_pptx( ) } \arguments{ -\item{input}{Path to Rmd, html, or pdf file of xaringan slides.} +\item{input}{Path to a Rmd, html, or pdf file, or a url of xaringan slides. +If the input is a url to xaringan slides on a website, you must provide the +full url ending in ".html".} \item{output_file}{Name of the output pptx file.} @@ -35,9 +37,8 @@ a new slide. Only used if `complex_slides = TRUE` or `partial_slides = TRUE`.} } \description{ -Build xaringan slides as pptx file from a Rmd, html, or pdf file. The -function builds to the pdf and then inserts a png image of each slide -as a new slide in a pptx file. +Build xaringan slides as a pptx file. The function builds to the pdf and +then inserts a png image of each slide as a new slide in a pptx file. } \examples{ \dontrun{ diff --git a/man/build_thumbnail.Rd b/man/build_thumbnail.Rd index 56551f3..5aad058 100644 --- a/man/build_thumbnail.Rd +++ b/man/build_thumbnail.Rd @@ -7,7 +7,9 @@ build_thumbnail(input, output_file = NULL) } \arguments{ -\item{input}{Path to Rmd or html file of xaringan slides.} +\item{input}{Path to a Rmd file or html file / url of xaringan slides. If +the input is a url to xaringan slides on a website, you must provide the +full url ending in ".html".} \item{output_file}{Name of the output png file.} }