st_aspdf: Render stable object to pdf file

View source: R/preview-standalone.R

st_aspdfR Documentation

Render stable object to pdf file

Description

Create a "standalone" pdf snippet from an stable object using the pdflatex utility. The resultant pdf file is saved on disk and the relative path to the file is returned. st2pdf() is an alias to st_as_pdf().

Usage

st_aspdf(
  x,
  stem = "pmt-standalone-preview",
  dir = tempdir(),
  font = "helvetica",
  textwidth = getOption("pmtables.textwidth", 6.5),
  border = getOption("pmtables.image.border", "0.2cm 0.7cm"),
  ntex = 1
)

st2pdf(
  x,
  stem = "pmt-standalone-preview",
  dir = tempdir(),
  font = "helvetica",
  textwidth = getOption("pmtables.textwidth", 6.5),
  border = getOption("pmtables.image.border", "0.2cm 0.7cm"),
  ntex = 1
)

Arguments

x

an stable object; this can be the result of calling stable() or stable_long().

stem

used to build intermediate and output file names.

dir

directory for building the pdf file.

font

the font to use; alternative values include roboto and utopia; passed to st_to_standalone().

textwidth

the page width (in inches) when building with pdflatex; passed to st_to_standalone(); see details.

border

passed as an option to standalone latex output type; see details.

ntex

number of times to build the pdf file

Details

The pdf file is built using pdflatex so this utility must be installed.

The textwidth argument is set to 6.5 inches by default to mimic a 8.5 x 11 page with 1 inch margins on the left and right. Setting textwidth sets the length of the ⁠\textwidth⁠ latex macro to that value and also inserts an invisible rule across the page with that width as well. This means for skinny tables, there will be whitespace on the left and right, but the font in the resultant images will be similar regardless of the width of the table. To skip setting the latex ⁠\textwidth⁠ macro, pass NULL.

The border argument can be one, two or four space-separated elements, each formatted as "<number><unit>" (e.g. "0.2cm"); pass one element to set the same border on all sides; two elements to set the border on left/right (first) and top/bottom (second); pass four elements to have separate borders for the left, bottom, right and top (see the documentation for the standalone latex package).

Value

A string containing the path to the rendered pdf file.

See Also

st_aspng(), st_as_image(), st_image_show()

Examples


# check that pdflatex is installed
## Not run: 
Sys.which("pdflatex")

## End(Not run)

## Not run: 
tab <- stable(stdata())
st_aspdf(tab)

## End(Not run)

# the template for building the image
temp <- system.file("tex", "standalone-preview.tex", package = "pmtables")
cat(temp, sep = "\n")


metrumresearchgroup/pmtables documentation built on Oct. 27, 2024, 5:16 p.m.