Package 'renderthis'

Title: Render Slides to Different Formats
Description: Render slides to different formats, including 'html', 'pdf', 'png', 'gif', 'pptx', and 'mp4', as well as a 'social' output, a 'png' of the first slide re-sized for sharing on social media.
Authors: John Helveston [aut, cre, cph] , Garrick Aden-Buie [aut] , Bryan Shalloway [ctb]
Maintainer: John Helveston <[email protected]>
License: MIT + file LICENSE
Version: 0.2.1
Built: 2024-11-08 11:29:28 UTC
Source: https://github.com/jhelvy/renderthis

Help Index


Build slides to multiple outputs.

Description

[Deprecated]

Build slides to multiple outputs. Options are "html", "social" "pdf", "png", "gif", "mp4", and "pptx". See each individual build_*() function for details about each output type.

Usage

build_all(
  input,
  include = c("html", "social", "pdf", "png", "gif", "mp4", "pptx"),
  exclude = NULL,
  complex_slides = FALSE,
  partial_slides = FALSE,
  delay = 1,
  density = 100,
  slides = "all",
  fps = 1
)

Arguments

input

Path to an .Rmd or .qmd file of slides.

include

A vector of the different output types to build. Options are "html", "social", "pdf", "png", "gif", "mp4", and "pptx". Defaults to c("html", "social", "pdf", "png", "gif", "mp4", "pptx").

exclude

A vector of the different output types to NOT build. Options are "html", "social", "pdf", "png", "gif", "mp4", and "pptx". Defaults to NULL, in which case all all output types are built.

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 the slides at a pace set by the delay argument. Requires a local installation of Chrome.

partial_slides

Should partial (continuation) slides be included in the output? If FALSE, the default, only the complete slide is included in the PDF.

delay

Seconds of delay between advancing to and printing a new slide. Only used if complex_slides = TRUE or partial_slides = TRUE.

density

Resolution of the resulting PNGs in each slide file. Defaults to 100.

slides

A numeric or integer vector of the slide number(s) to render as PNG files , or one of "all", "first", or "last". Negative integers select which slides not to include. If more than one slide are included, PNGs will be returned as a ZIP file. Defaults to "all", in which case all slides are included.

fps

Frames per second of the resulting .mp4 file.

Value

Builds slides to multiple output formats.

Examples

if (interactive()) {
    # Both of these build html and pdf outputs
    # (PDF outputs require Google Chrome for {pagedown})
    with_example("slides.Rmd", requires_chrome = TRUE, {
        build_all("slides.Rmd", include = c("html", "pdf"))
    })
}

Render slides as a GIF file.

Description

Render slides as a GIF video file. The function renders to the PDF, converts each slide in the PDF to a PNG, and then converts the deck of PNG files to a GIF file.

Usage

to_gif(
  from,
  to = NULL,
  density = 100,
  slides = "all",
  fps = 1,
  complex_slides = FALSE,
  partial_slides = FALSE,
  delay = 1,
  keep_intermediates = FALSE
)

Arguments

from

Path to an .Rmd, .qmd, .html, .pdf file, or a URL. If from is a URL to slides on a website, you must provide the full URL ending in ".html".

to

Name of the output .gif file.

density

Resolution of the resulting PNGs in each slide file. Defaults to 100.

slides

A numeric or integer vector of the slide number(s) to include in the GIF, or one of "all", "first", or "last". Negative integers select which slides not to include. Defaults to "all", in which case all slides are included.

fps

Frames per second in the animated GIF.

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 the slides at a pace set by the delay argument. Requires a local installation of Chrome.

partial_slides

Should partial (continuation) slides be included in the output? If FALSE, the default, only the complete slide is included in the PDF.

delay

Seconds of delay between advancing to and printing a new slide. Only used if complex_slides = TRUE or partial_slides = TRUE.

keep_intermediates

Should we keep the intermediate files used to render the final output? The default is FALSE.

Value

Slides are rendered as a .gif file.

Examples

with_example("slides.Rmd", requires_chrome = TRUE, {
    # Render gif from Rmd, html, pdf, or direct URL
    to_gif("slides.Rmd")
})

Render slides as html file.

Description

Render xaringan or Quarto slides as an html file. In generally, it is the same thing as rmarkdown::render() or quarto::quarto_render() except that the self_contained option is forced to TRUE if the HTML file is built into a directory other than the one containing from.

Usage

to_html(from, to = NULL, self_contained = FALSE, render_args = NULL)

Arguments

from

Path to an .Rmd or .qmd file.

to

The name of the output file. If using NULL then the output file name will be based on file name for the from file. If a file name is provided, a path to the output file can also be provided.

self_contained

Should the output file be a self-contained HTML file where all images, CSS and JavaScript are included directly in the output file? This option, when TRUE, provides you with a single HTML file that you can share with others, but it may be very large. This feature is enabled by default when the to file is written in a directory other than the one containing the from R Markdown file.

render_args

A list of arguments passed to rmarkdown::render() or quarto::quarto_render().

Value

Slides are rendered as an .html file.

Examples

with_example("slides.Rmd", {
    # Render html from Rmd file
    to_html("slides.Rmd")
})

Render slides as an MP4 video file.

Description

Render slides as an MP4 video file. The function renders to the pdf, converts each slide in the pdf to a png, and then converts the deck of png files to a MP4 video file.

Usage

to_mp4(
  from,
  to = NULL,
  density = 100,
  slides = "all",
  fps = 1,
  complex_slides = FALSE,
  partial_slides = FALSE,
  delay = 1,
  keep_intermediates = FALSE
)

Arguments

from

Path to an .Rmd, .qmd, .html, .pdf file, or a URL. If from is a URL to slides on a website, you must provide the full URL ending in ".html".

to

Name of the output .mp4 file.

density

Resolution of the resulting PNGs in each slide file. Defaults to 100.

slides

A numeric or integer vector of the slide number(s) to include in the mp4, or one of "all", "first", or "last". Negative integers select which slides not to include. Defaults to "all", in which case all slides are included.

fps

Frames per second of the resulting .mp4 file.

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 the slides at a pace set by the delay argument. Requires a local installation of Chrome.

partial_slides

Should partial (continuation) slides be included in the output? If FALSE, the default, only the complete slide is included in the PDF.

delay

Seconds of delay between advancing to and printing a new slide. Only used if complex_slides = TRUE or partial_slides = TRUE.

keep_intermediates

Should we keep the intermediate files used to render the final output? The default is FALSE.

Value

Slides are rendered as an .mp4 file.

Examples

with_example("slides.Rmd", requires_chrome = TRUE, requires_packages = "av", {
    # Render mp4 from Rmd, html, pdf, or direct URL
    to_mp4("slides.Rmd")
})

Render slides as PDF file.

Description

Render 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 and pdftools packages.

Usage

to_pdf(
  from,
  to = NULL,
  complex_slides = FALSE,
  partial_slides = FALSE,
  delay = 1,
  keep_intermediates = NULL
)

Arguments

from

Path to an .Rmd, .qmd, .html file, or a URL. If from is a URL to slides on a website, you must provide the full URL ending in ".html".

to

The name of the output .pdf file. If NULL (the default) then the output filename will be based on filename for the from file. If a filename is provided, a path to the output file can also be provided.

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 the slides at a pace set by the delay argument. Requires a local installation of Chrome.

partial_slides

Should partial (continuation) slides be included in the output? If FALSE, the default, only the complete slide is included in the PDF.

delay

Seconds of delay between advancing to and printing a new slide. Only used if complex_slides = TRUE or partial_slides = TRUE.

keep_intermediates

Should we keep the intermediate HTML file? Only relevant if the from file is an .Rmd file. Default is TRUE if the to file is written into the same directory as the from argument, otherwise the intermediate file isn't kept.

Value

Slides are rendered as a .pdf file.

Examples

with_example("slides.Rmd", requires_chrome = TRUE, {
    # Render pdf from Rmd, html, or direct URL
    to_pdf("slides.Rmd")
})

Render slides as PNG file(s).

Description

Render PNG image(s) of slides. The function renders to the PDF and then converts it into PNG files of each slide. The slide numbers defined by the slides argument are saved (defaults to 1, returning only the title slide). If length(slides) > 1, it will return the PNG files in a ZIP file. You can also get a ZIP file of all the slides as PNGs by setting slides = "all").

Usage

to_png(
  from,
  to = NULL,
  density = 100,
  slides = 1,
  complex_slides = FALSE,
  partial_slides = FALSE,
  delay = 1,
  keep_intermediates = FALSE
)

Arguments

from

Path to an .Rmd, .qmd, .html, .pdf file, or a URL. If from is a URL to slides on a website, you must provide the full URL ending in ".html".

to

Name of the output .png or .zip file.

density

Resolution of the resulting PNGs in each slide file. Defaults to 100.

slides

A numeric or integer vector of the slide number(s) to render as PNG files , or one of "all", "first", or "last". Negative integers select which slides not to include. If more than one slide are included, PNGs will be returned as a ZIP file. Defaults to "all", in which case all slides are included.

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 the slides at a pace set by the delay argument. Requires a local installation of Chrome.

partial_slides

Should partial (continuation) slides be included in the output? If FALSE, the default, only the complete slide is included in the PDF.

delay

Seconds of delay between advancing to and printing a new slide. Only used if complex_slides = TRUE or partial_slides = TRUE.

keep_intermediates

Should we keep the intermediate files used to render the final output? The default is FALSE.

Value

Slides are rendered as a .png file (single) or .zip file of multiple .png files.

Examples

with_example("slides.Rmd", requires_chrome = TRUE, {
    # By default a png of only the first slide is built
    to_png("slides.Rmd", keep_intermediates = TRUE)

    # or render a zip file of multiple or all slides (`slides = "all"`)
    to_png("slides.pdf", slides = c(1, 3, 5))
})

Render slides as a PowerPoint file.

Description

Render slides as a .pptx file. The function renders to the PDF and then converts it into PNG images that are inserted on each slide in the PowerPoint file.

Usage

to_pptx(
  from,
  to = NULL,
  density = 100,
  slides = "all",
  complex_slides = FALSE,
  partial_slides = FALSE,
  delay = 1,
  keep_intermediates = FALSE,
  ratio = NULL
)

Arguments

from

Path to an .Rmd, .qmd, .html, .pdf file, or a URL. If from is a URL to slides on a website, you must provide the full URL ending in ".html".

to

Name of the output .pptx file.

density

Resolution of the resulting PNGs in each slide file. Defaults to 100.

slides

A numeric or integer vector of the slide number(s) to include in the pptx, or one of "all", "first", or "last". Negative integers select which slides not to include. Defaults to "all", in which case all slides are included.

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 the slides at a pace set by the delay argument. Requires a local installation of Chrome.

partial_slides

Should partial (continuation) slides be included in the output? If FALSE, the default, only the complete slide is included in the PDF.

delay

Seconds of delay between advancing to and printing a new slide. Only used if complex_slides = TRUE or partial_slides = TRUE.

keep_intermediates

Should we keep the intermediate files used to render the final output? The default is FALSE.

ratio

PowerPoint slides ratio. Possible values are "4:3", "16:9". Default to NULL, meaning it will be guessed frm the slides.

Value

Slides are rendered as a pptx file.

Examples

with_example("slides.Rmd", requires_chrome = TRUE, requires_packages = "officer", {
    # Render pptx from Rmd, html, pdf, or direct URL
    to_pptx("slides.Rmd")
})

Render png image of first slide sized for social media sharing.

Description

Render png image of first slide for sharing on social media. Requires a local installation of Chrome as well as the webshot2 package: remotes::install_github("rstudio/webshot2").

Usage

to_social(from, to = NULL)

Arguments

from

Path to Rmd file of input media (e.g., xaringan slides).

to

The name of the output file. If using NULL then the output filename will be based on filename for the from file. If a filename is provided, a path to the output file can also be provided.

Value

Slides are rendered as a png file.

Examples

if (interactive()) {
    with_example("slides.Rmd", requires_chrome = TRUE, requires_packages = "webshot2", {
        # Render png image of first slide from Rmd file
        # sized for sharing on social media
        to_social("slides.Rmd")
    })
}