Skip to content

Commit

Permalink
added assert_chrome_installed() for issue #12; updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jhelvy committed Feb 18, 2021
1 parent 1ed69ce commit d8e5781
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 15 deletions.
2 changes: 1 addition & 1 deletion R/all.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Build xaringan slides to multiple outputs.
#'
#' Build xaringan slides to multiple outputs. Options are `"html"`, `"pdf"`,
#' `"gif"`, `"pptx"`, and `"thumbnail"` (a png image of the first slide).
#' `"gif"`, `"pptx"`, `"thumbnail"`, and `"social"`.
#' @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
Expand Down
3 changes: 3 additions & 0 deletions R/gif.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#' 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.
#' @param output_file Name of the output gif file.
#' @param density Resolution of the resulting gif file.
Expand Down
3 changes: 3 additions & 0 deletions R/html.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#' Build xaringan slides as html file.
#'
#' Build xaringan slides as html file. Essentially the same thing as
#' `rmarkdown::render()` with `output_format = "xaringan::moon_reader"`
#' @param input Path to Rmd file of xaringan slides.
#' @param output_file The name of the output file. If using NULL then
#' the output filename will be based on filename for the input file.
Expand Down
10 changes: 9 additions & 1 deletion R/pdf.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#' Prints xaringan slides to a PDF file.
#' Build xaringan slides as pdf file.
#'
#' Build xaringan slides to 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.
#' @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.
Expand Down Expand Up @@ -48,6 +53,9 @@ build_pdf <- function(
partial_slides = FALSE,
delay = 1
) {
# Check if Chrome is installed
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")
Expand Down
4 changes: 4 additions & 0 deletions R/pptx.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#' 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.
#' @param output_file Name of the output pptx file.
#' @param density Resolution of the resulting pptx file.
Expand Down
8 changes: 7 additions & 1 deletion R/social.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# build_social() was inspired by this function from gadenbuie's blog:
# https://www.garrickadenbuie.com/blog/sharing-xaringan-slides/#the-perfect-share-image-ratio

#' Build png image of first slide sized for social media sharing.
#'
#' Build png image of first xaringan slide for sharing on social media.
#' Requires a local installation of Chrome.
#' Requires a local installation of Chrome as well as the {webshot2} package:
#' `remotes::install_github("rstudio/webshot2")`.
#' @param input Path to Rmd file of xaringan slides.
#' @param output_file The name of the output file. If using NULL then
#' the output filename will be based on filename for the input file.
Expand All @@ -23,6 +26,9 @@ build_social <- function(input, output_file = NULL) {
)
}

# Check if Chrome is installed
assert_chrome_installed()

# Check input and output files have correct extensions
assert_path_ext(input, "rmd", arg = "input")
output_null <- is.null(output_file)
Expand Down
8 changes: 7 additions & 1 deletion R/thumbnail.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#' Build png thumbnail image of first xaringan slide.
#' Build png thumbnail image of first slide.
#'
#' 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 output_file Name of the output png file.
#' @export
Expand All @@ -10,6 +13,9 @@
#' }
build_thumbnail <- function(input, output_file = NULL) {

# Check if Chrome is installed
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)
Expand Down
16 changes: 16 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,19 @@ 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) }
)
if (is.null(chromePath)) {
stop(error)
}
}
2 changes: 1 addition & 1 deletion man/build_all.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/build_gif.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/build_html.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions man/build_pdf.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/build_pptx.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/build_social.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/build_thumbnail.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d8e5781

Please sign in to comment.