Title: | Convert Tables to PDF or PNG |
---|---|
Description: | Converts table-like objects to stand-alone PDF or PNG. Can be used to embed tables and arbitrary content in PDF or Word documents. Provides a low-level R interface for creating 'LaTeX' code, e.g. command() and a high-level interface for creating PDF documents, e.g. as.pdf.data.frame(). Extensive customization is available via mid-level functions, e.g. as.tabular(). See also 'package?latexpdf'. Support for PNG is experimental; see 'as.png.data.frame'. Adapted from 'metrumrg' <https://r-forge.r-project.org/R/?group_id=1215>. Requires a compatible installation of 'pdflatex', e.g. <https://miktex.org/>. |
Authors: | Tim Bergsma |
Maintainer: | Tim Bergsma <[email protected]> |
License: | GPL-3 |
Version: | 0.1.8 |
Built: | 2024-10-25 22:13:49 UTC |
Source: | https://github.com/bergsmat/latexpdf |
latexpdf helps you create pdf documents in R using LaTeX techniques; this is especially useful for making stand-alone PDF images of data.frames. For report-length PDF, some flavor of markup or markdown (e.g. Sweave, Rmarkdown) is probably a more attractive mechanism for the main document; in this context, latexpdf can be used to embed tables with the same aesthetics as stand-alone versions.
"Anything in LaTeX can be expressed in terms of commands and environments", (<http://en.wikibooks.org/wiki/LaTeX/Absolute_Beginners>). Accordingly, latexpdf provides R functions to generate LaTeX commands (command()) and environments (wrap()). For commands, care is taken to support options and arguments. These can be used to create character vectors containing arbitrary LaTeX code.
In fact, the package itself uses these functions to convert data frames to LaTeX code, providing reasonable defaults and supporting many aesthetic interventions. See '?as.tabular' and '?as.ltable' (tabular and table environments, respectively). See also 'vignette('tabular') for a demonstration of options.
While latexpdf can be useful for low-level operations, creating PDF documents directly is more powerful. Pre-generated LaTeX code can be inserted into literate programming documents (Sweave, Rmarkdown) or can be auto-converted to stand-alone PDF documents (see especially '?as.pdf.data.frame'). Functions tex2pdf() and viewtex() create and visualize arbitrary tex code by converting to PDF documents. They rely on as.pdf.document(), which places a system call to 'pdflatex'.
Some file formats, such as MS Word and Powerpoint, cannot embed PDF images. Experimental support is available for converting PDF to PNG. For example, if you switch from Rmarkdown's pdf_document() to word_document(), you may want to switch from as.pdf() to as.png() for your images. PNG functionality relies requires the local Ghostscript installation (see '?ghostconvert') which is almost certainly present if 'pdflatex' is. Ghostscript may be hard to find. See '?tools::find_gs_cmd'; for Miktex installations, consider 'find_gs_cmd(gs_cmd = 'mgs')'.
Tim Bergsma, [email protected]
Coerces to LaTeX document. Generic, with methods for character and data.frame.
Coerces to LaTex document from character.
Coerces to LaTeX document from data.frame.
as.document(x, ...) ## S3 method for class 'character' as.document( x, preamble = makePreamble(...), thispagestyle = command("thispagestyle", args = "empty"), pagestyle = command("pagestyle", args = "empty"), prolog = NULL, epilog = NULL, ... ) ## S3 method for class 'data.frame' as.document( x, rules = c(2, 1, 1), walls = 0, grid = FALSE, rowgroups = factor(rownames(x)), colgroups = factor(names(x)), rowbreaks = if (grid) breaks(rowgroups, ...) else 0, colbreaks = if (grid) breaks(colgroups, ...) else 0, rowcolors = NULL, charjust = "left", numjust = "right", justify = ifelse(sapply(x, is.numeric), numjust, charjust), colwidth = NA, paralign = "top", na = "", verbatim = ifelse(sapply(x, is.numeric), TRUE, FALSE), escape = "#", reserve = TRUE, trim = TRUE, wide = NULL, long = NULL, wider = 0, longer = 0, ... )
as.document(x, ...) ## S3 method for class 'character' as.document( x, preamble = makePreamble(...), thispagestyle = command("thispagestyle", args = "empty"), pagestyle = command("pagestyle", args = "empty"), prolog = NULL, epilog = NULL, ... ) ## S3 method for class 'data.frame' as.document( x, rules = c(2, 1, 1), walls = 0, grid = FALSE, rowgroups = factor(rownames(x)), colgroups = factor(names(x)), rowbreaks = if (grid) breaks(rowgroups, ...) else 0, colbreaks = if (grid) breaks(colgroups, ...) else 0, rowcolors = NULL, charjust = "left", numjust = "right", justify = ifelse(sapply(x, is.numeric), numjust, charjust), colwidth = NA, paralign = "top", na = "", verbatim = ifelse(sapply(x, is.numeric), TRUE, FALSE), escape = "#", reserve = TRUE, trim = TRUE, wide = NULL, long = NULL, wider = 0, longer = 0, ... )
x |
object to be converted, typically data.frame (paths of tex files for |
... |
passed to |
preamble |
latex markup to include before beginning the document |
thispagestyle |
thispagestyle command |
pagestyle |
pagestyle command |
prolog |
latex markup to include before x |
epilog |
latex markup to include after x |
rules |
numeric; will be recycled to length 3. indicates number of horizontal lines above and below the header, and below the last row. |
walls |
numeric, recycled to length 2. Number of vertical lines on left and right of table. |
grid |
logical, whether to have lines between rows and columns |
rowgroups |
a vector as long as nrow(x), non-repeats trigger horizontal lines |
colgroups |
a vector as long as names(x), non-repeats trigger vertical lines |
rowbreaks |
numeric: a manual way to specify numbers of lines between rows (ignores grid and rowgroups) |
colbreaks |
numeric: a manual way to specify numbers of lines between columns (ignores grid and colgroups) |
rowcolors |
character vector of color names, recycled as necessary to color all rows (NULL: no color) |
charjust |
default justification for character columns |
numjust |
default justification for numeric columns |
justify |
manual specification of column justifications: left, right, center, or decimal (vector as long as ncol(x)) |
colwidth |
manual specification of column width. (vector of length ncol(x).) Overrides |
paralign |
used with colwidth to align paragraphs: top, middle, or bottom. |
na |
string to replace NA elements |
verbatim |
whether to use verbatim environment for numeric fields. Makes sense for decimal justification; interacts with |
escape |
symbol used by ‘verb’ command as delimiter. A warning is issued if it is found in non-NA text. |
reserve |
substitute escape sequences for LaTeX reserved characters |
trim |
passed to the format command: true by default, so that alignment is the responsibility of just the tabular environment arguments |
wide |
nominal page width in mm |
long |
nominal page length in mm |
wider |
additional page width in mm |
longer |
additional page lenth in mm |
character
character
character
as.document(character)
: character method
as.document(data.frame)
: data.frame method
as.document(head(Theoph))
as.document(head(Theoph))
Coerces to LaTeX table environment. Generic, with methods for data.frame, table, and matrix.
Coerces to LaTeX table from data.frame. See details.
Coerces to ltable from table, reclassifying its argument as matrix.
Coerces to ltable from matrix; tires to capture the column names as a caption, and (like as.tabular.matrix
) converts its argument to data.frame, capturing rownames as a column in the first position if rownames are suitably named.
as.ltable(x, ...) ## S3 method for class 'data.frame' as.ltable( x, caption = NULL, cap = caption, cap.top = TRUE, label = NULL, options = "H", environments = "center", source = NULL, file = NULL, source.label = "source: ", file.label = "file: ", basefile = FALSE, footnote.size = "tiny", ... ) ## S3 method for class 'table' as.ltable(x, ...) ## S3 method for class 'matrix' as.ltable(x, caption = names(dimnames(x))[[2]], ...)
as.ltable(x, ...) ## S3 method for class 'data.frame' as.ltable( x, caption = NULL, cap = caption, cap.top = TRUE, label = NULL, options = "H", environments = "center", source = NULL, file = NULL, source.label = "source: ", file.label = "file: ", basefile = FALSE, footnote.size = "tiny", ... ) ## S3 method for class 'table' as.ltable(x, ...) ## S3 method for class 'matrix' as.ltable(x, caption = names(dimnames(x))[[2]], ...)
x |
object |
... |
passed arguments |
caption |
full version of the caption |
cap |
short version of the caption, for list of tables |
cap.top |
Should caption be placed at the top, instead of bottom? |
label |
optional label |
options |
options for latex table environment, e.g. H or !htpb |
environments |
extra environments to nest between ‘table’ and ‘tabular’ |
source |
optional source attribution |
file |
optional file name |
source.label |
optional text to preceed source if specified |
file.label |
optional text to preceed file if specified |
basefile |
if TRUE, strip path from file for display purposes |
footnote.size |
font size for source and file, etc. |
Converts data.frame to tabular, then wraps it in specified environments, then wraps result in a latex table environment. Result is returned visibly, or if file
is specified it is printed to file and returned invisibly.
If source
and source.label
are defined, they will be printed in a tiny font immediately under the table (bound to the tabular element). If file
and file.label
are defined as well, they will be printed (tiny) under source. Set source.label
to NULL to suppress embedding of source
; set to empty string to suppress source label. Set file.label
to NULL to suppress embedding of file
; set to empty string to suppress file label. Note that file
controls file destination, whether or not represented in the result.
Extra arguments(...) are passed to as.tabular
.
character
as.ltable(data.frame)
: data.frame method
as.ltable(table)
: table method
as.ltable(matrix)
: matrix method
as.ltable(head(Theoph)) as.ltable(table(1:3,4:6))
as.ltable(head(Theoph)) as.ltable(table(1:3,4:6))
Coerces to PDF. Generic, with methods for character, document, and data.frame.
Coerces to PDF from document. Makes a system call to 'pdflatex'. Extra arguments ignored.
Coerces character to document and then to PDF. Extra arguments passed to as.document.character
and as.pdf.document
.
as.pdf(x, ...) ## S3 method for class 'document' as.pdf( x, stem = "latexpdf-doc", dir = ".", clean = TRUE, ignore.stdout = FALSE, ignore.stderr = FALSE, show.output.on.console = TRUE, ... ) ## S3 method for class 'character' as.pdf(x, stem, ...)
as.pdf(x, ...) ## S3 method for class 'document' as.pdf( x, stem = "latexpdf-doc", dir = ".", clean = TRUE, ignore.stdout = FALSE, ignore.stderr = FALSE, show.output.on.console = TRUE, ... ) ## S3 method for class 'character' as.pdf(x, stem, ...)
x |
object |
... |
passed arguments |
stem |
the stem of a file name (no extension) |
dir |
output directory |
clean |
whether to delete system files after pdf creation |
ignore.stdout |
passed to |
ignore.stderr |
passed to |
show.output.on.console |
passed to |
the output file path (invisible)
as.pdf(document)
: document method
as.pdf(character)
: character method
Coerces data.frame to document and then to PDF.
Extra arguments are passed to makePreamble
.
as.document.data.frame
will try to guess an
appropriate width and length( wide
, long
)
for the page, but you may need something wider
or
longer
, especially if you adjust aesthetics.
Negative values for wider
and longer
are meaningful.
## S3 method for class 'data.frame' as.pdf( x, rules = c(2, 1, 1), walls = 0, grid = FALSE, rowgroups = factor(rownames(x)), colgroups = factor(names(x)), rowbreaks = if (grid) breaks(rowgroups) else 0, colbreaks = if (grid) breaks(colgroups) else 0, rowgrouprule = 0, colgrouprule = 0, rowcolors = NULL, rowgrouplabel = " ", charjust = "left", numjust = "right", justify = ifelse(sapply(x, is.numeric), numjust, charjust), colwidth = NA, paralign = "top", na = "", verbatim = ifelse(sapply(x, is.numeric), TRUE, FALSE), escape = "#", reserve = TRUE, trim = TRUE, source = NULL, file = NULL, source.label = "source: ", file.label = "file: ", basefile = FALSE, tabularEnvironment = "tabular", footnote.size = "tiny", geoLeft = "1mm", geoRight = "1mm", geoTop = "1mm", geoBottom = "1mm", wide = NULL, long = NULL, wider = 0, longer = 0, thispagestyle = command("thispagestyle", args = "empty"), pagestyle = command("pagestyle", args = "empty"), prolog = NULL, epilog = NULL, stem = "latexpdf-doc", dir = ".", clean = TRUE, ... )
## S3 method for class 'data.frame' as.pdf( x, rules = c(2, 1, 1), walls = 0, grid = FALSE, rowgroups = factor(rownames(x)), colgroups = factor(names(x)), rowbreaks = if (grid) breaks(rowgroups) else 0, colbreaks = if (grid) breaks(colgroups) else 0, rowgrouprule = 0, colgrouprule = 0, rowcolors = NULL, rowgrouplabel = " ", charjust = "left", numjust = "right", justify = ifelse(sapply(x, is.numeric), numjust, charjust), colwidth = NA, paralign = "top", na = "", verbatim = ifelse(sapply(x, is.numeric), TRUE, FALSE), escape = "#", reserve = TRUE, trim = TRUE, source = NULL, file = NULL, source.label = "source: ", file.label = "file: ", basefile = FALSE, tabularEnvironment = "tabular", footnote.size = "tiny", geoLeft = "1mm", geoRight = "1mm", geoTop = "1mm", geoBottom = "1mm", wide = NULL, long = NULL, wider = 0, longer = 0, thispagestyle = command("thispagestyle", args = "empty"), pagestyle = command("pagestyle", args = "empty"), prolog = NULL, epilog = NULL, stem = "latexpdf-doc", dir = ".", clean = TRUE, ... )
x |
data.frame |
rules |
numeric; will be recycled to length 3. indicates number of horizontal lines above and below the header, and below the last row. |
walls |
numeric, recycled to length 2. Number of vertical lines on left and right of table. |
grid |
logical, whether to have lines between rows and columns |
rowgroups |
a vector as long as nrow(x), non-repeats trigger horizontal lines |
colgroups |
a vector as long as names(x), non-repeats trigger vertical lines |
rowbreaks |
numeric: a manual way to specify numbers of lines between rows (ignores grid and rowgroups) |
colbreaks |
numeric: a manual way to specify numbers of lines between columns (ignores grid and colgroups) |
rowgrouprule |
number of lines to set off row group column, if rowgroups supplied as character |
colgrouprule |
number of lines to set off col group header, if colgroups supplied as character |
rowcolors |
character vector of color names, recycled as necessary to color all rows (NULL: no color); not compatible with rowgroups |
rowgrouplabel |
character string (at least one character) to label rowgroup column |
charjust |
default justification for character columns |
numjust |
default justification for numeric columns |
justify |
manual specification of column justifications: left, right, center, or decimal (vector as long as ncol(x)) |
colwidth |
manual specification of column width. (vector of length ncol(x).) Overrides |
paralign |
used with colwidth to align paragraphs: top, middle, or bottom. |
na |
string to replace NA elements |
verbatim |
whether to use verbatim environment for numeric fields. Makes sense for decimal justification; interacts with |
escape |
symbol used by ‘verb’ command as delimiter. A warning is issued if it is found in non-NA text. |
reserve |
substitute escape sequences for LaTeX reserved characters |
trim |
passed to the format command: true by default, so that alignment is the responsibility of just the tabular environment arguments |
source |
optional source attribution |
file |
optional file name |
source.label |
optional text to preceed source if specified |
file.label |
optional text to preceed file if specified |
basefile |
if TRUE, strip path from file for display purposes |
tabularEnvironment |
default |
footnote.size |
font size for source and file attributions |
geoLeft |
geometry package: left margin |
geoRight |
geometry package: right margin |
geoTop |
geometry package: top margin |
geoBottom |
geometry package: bottom margin |
wide |
nominal page width in mm |
long |
nominal page length in mm |
wider |
additional page width in mm |
longer |
additional page lenth in mm |
thispagestyle |
thispagestyle command |
pagestyle |
pagestyle command |
prolog |
latex markup to include before x |
epilog |
latex markup to include after x |
stem |
the stem of a file name (no extension) |
dir |
output directory |
clean |
whether to delete system files after pdf creation |
... |
passed eventually to |
## Not run: as.pdf(head(Theoph)) ## Not run: as.pdf(Theoph[0,])
## Not run: as.pdf(head(Theoph)) ## Not run: as.pdf(Theoph[0,])
Coerces to PNG. Generic, with methods for character, document, and data.frame.
Coerces to PNG from document. Makes a system call to 'pdflatex', converts resulting file to PNG. Extra arguments passed to as.pdf.document
and ghostconvert
.
Coerces character to document, PDF, and then PNG. Extra arguments passed to as.document.character
and as.png.document
.
as.png(x, ...) ## S3 method for class 'document' as.png( x, stem = "latexpdf-doc", dir = ".", clean = TRUE, replace = TRUE, multipage = TRUE, ... ) ## S3 method for class 'character' as.png(x, stem, ...)
as.png(x, ...) ## S3 method for class 'document' as.png( x, stem = "latexpdf-doc", dir = ".", clean = TRUE, replace = TRUE, multipage = TRUE, ... ) ## S3 method for class 'character' as.png(x, stem, ...)
x |
object |
... |
passed arguments |
stem |
the stem of a file name (no extension) |
dir |
output directory |
clean |
whether to delete system files after PNG creation |
replace |
whether to delete the pdf file |
multipage |
whether to convert multiple pages of the PDF |
as.png(document)
: document method
as.png(character)
: character method
as.pdf.document
ghostconvert
Coerces to PNG from 'data.frame'.
## S3 method for class 'data.frame' as.png(x, replace = TRUE, ...)
## S3 method for class 'data.frame' as.png(x, replace = TRUE, ...)
x |
data.frame |
replace |
whether to delete the intermediate PDF if successful |
... |
passed to |
path to the file created
## Not run: browseURL(as.png(head(Theoph), dir = tempdir(), gs_cmd = 'mgs')) ## End(Not run)
## Not run: browseURL(as.png(head(Theoph), dir = tempdir(), gs_cmd = 'mgs')) ## End(Not run)
Coerces to tabular. Generic, with methods for data.frame, table, and matrix.
Coerces to tabular from data.frame. Extra arguments passed to format.data.frame
.
Coerces to tabular from table.
Coerces to tabular from matrix.
as.tabular(x, ...) ## S3 method for class 'data.frame' as.tabular( x, rules = c(2, 1, 1), walls = 0, grid = FALSE, rowgroups = factor(rownames(x)), colgroups = factor(names(x)), rowbreaks = if (grid) breaks(rowgroups) else 0, colbreaks = if (grid) breaks(colgroups) else 0, rowgrouprule = 0, colgrouprule = 0, rowcolors = NULL, rowgrouplabel = " ", charjust = "left", numjust = "right", justify = ifelse(sapply(x, is.numeric), numjust, charjust), decimal.mark = getOption("OutDec"), colwidth = NA, paralign = "top", na = "", verbatim = ifelse(sapply(x, is.numeric), TRUE, FALSE), escape = "#", reserve = TRUE, trim = TRUE, source = NULL, file = NULL, source.label = "source: ", file.label = "file: ", basefile = FALSE, tabularEnvironment = "tabular", footnote.size = "tiny", ... ) ## S3 method for class 'table' as.tabular(x, ...) ## S3 method for class 'matrix' as.tabular(x, ...)
as.tabular(x, ...) ## S3 method for class 'data.frame' as.tabular( x, rules = c(2, 1, 1), walls = 0, grid = FALSE, rowgroups = factor(rownames(x)), colgroups = factor(names(x)), rowbreaks = if (grid) breaks(rowgroups) else 0, colbreaks = if (grid) breaks(colgroups) else 0, rowgrouprule = 0, colgrouprule = 0, rowcolors = NULL, rowgrouplabel = " ", charjust = "left", numjust = "right", justify = ifelse(sapply(x, is.numeric), numjust, charjust), decimal.mark = getOption("OutDec"), colwidth = NA, paralign = "top", na = "", verbatim = ifelse(sapply(x, is.numeric), TRUE, FALSE), escape = "#", reserve = TRUE, trim = TRUE, source = NULL, file = NULL, source.label = "source: ", file.label = "file: ", basefile = FALSE, tabularEnvironment = "tabular", footnote.size = "tiny", ... ) ## S3 method for class 'table' as.tabular(x, ...) ## S3 method for class 'matrix' as.tabular(x, ...)
x |
object |
... |
passed arguments |
rules |
numeric; will be recycled to length 3. indicates number of horizontal lines above and below the header, and below the last row. |
walls |
numeric, recycled to length 2. Number of vertical lines on left and right of table. |
grid |
logical, whether to have lines between rows and columns |
rowgroups |
a vector as long as nrow(x), non-repeats trigger horizontal lines |
colgroups |
a vector as long as names(x), non-repeats trigger vertical lines |
rowbreaks |
numeric: a manual way to specify numbers of lines between rows (ignores grid and rowgroups) |
colbreaks |
numeric: a manual way to specify numbers of lines between columns (ignores grid and colgroups) |
rowgrouprule |
number of lines to set off row group column, if rowgroups supplied as character |
colgrouprule |
number of lines to set off col group header, if colgroups supplied as character |
rowcolors |
character vector of color names, recycled as necessary to color all rows (NULL: no color) |
rowgrouplabel |
character string (at least one character) to label rowgroup column |
charjust |
default justification for character columns |
numjust |
default justification for numeric columns |
justify |
manual specification of column justifications: left, right, center, or decimal (vector as long as ncol(x)) |
decimal.mark |
passed to |
colwidth |
manual specification of column width. (vector of length ncol(x).) Overrides |
paralign |
used with colwidth to align paragraphs: top, middle, or bottom. |
na |
string to replace NA elements |
verbatim |
whether to use verbatim environment for numeric fields. Makes sense for decimal justification; interacts with |
escape |
symbol used by ‘verb’ command as delimiter. A warning is issued if it is found in non-NA text. |
reserve |
substitute escape sequences for LaTeX reserved characters |
trim |
passed to the format command: true by default, so that alignment is the responsibility of just the tabular environment arguments |
source |
optional source attribution |
file |
optional file name |
source.label |
optional text to preceed source if specified |
file.label |
optional text to preceed file if specified |
basefile |
if TRUE, strip path from file for display purposes |
tabularEnvironment |
default |
footnote.size |
font size for source and file attributions |
tabular
as.tabular(data.frame)
: data.frame method
as.tabular(table)
: table method
as.tabular(matrix)
: matrix method
as.tabular(head(Theoph)) as.tabular(table(1:3,4:6)) as.tabular(head(Theoph,source='foo/bar',footnote.size='huge')) ## Not run: as.pdf(head(Theoph))
as.tabular(head(Theoph)) as.tabular(table(1:3,4:6)) as.tabular(head(Theoph,source='foo/bar',footnote.size='huge')) ## Not run: as.pdf(head(Theoph))
Calculates row and column breaks by finding first elements among repeats.
breaks(x, ...)
breaks(x, ...)
x |
vector |
... |
ignored |
integer
Format a latex command. x
is formated as a latex command, with the options (possibly named) inserted in square brackets, and the arguments each enclosed in curly braces. depth
spaces are added to the left end of the string.
command(x, options = NULL, args = NULL, depth = 0)
command(x, options = NULL, args = NULL, depth = 0)
x |
length one character |
options |
vector or list |
args |
vector or list |
depth |
integer |
character
command('caption',options='short',args='long')
command('caption',options='short',args='long')
Call Ghostscript, converting by default from PDF to PNG.
ghostconvert( x, y = file.path(gdir, out), gdir = dirname(x), out = sub("\\.[^.]+$", paste0(if (multipage) multifix else NULL, ".", suffix), basename(x)), gs_cmd = "", device = "pngalpha", multipage = FALSE, multifix = "-%03d", suffix = "png", antialias = 4, resolution = 300, replace = TRUE, other = "", ... )
ghostconvert( x, y = file.path(gdir, out), gdir = dirname(x), out = sub("\\.[^.]+$", paste0(if (multipage) multifix else NULL, ".", suffix), basename(x)), gs_cmd = "", device = "pngalpha", multipage = FALSE, multifix = "-%03d", suffix = "png", antialias = 4, resolution = 300, replace = TRUE, other = "", ... )
x |
path for file to be converted |
y |
path for output file |
gdir |
directory for png output |
out |
filename for output file |
gs_cmd |
passed to |
device |
output device type |
multipage |
whether to convert multiple pages |
multifix |
a filename suffix when converting multiple pages |
suffix |
file extension for output |
antialias |
font antialiasing |
resolution |
raster image resolution |
replace |
whether to delete |
other |
other arguments to ghostscript |
... |
ignored |
the name of the file created
## Not run: pdf <- as.pdf(head(Theoph),dir = tempdir()) png <- ghostconvert(pdf, gs_cmd = 'mgs') browseURL(png) ## End(Not run)
## Not run: pdf <- as.pdf(head(Theoph),dir = tempdir()) png <- ghostconvert(pdf, gs_cmd = 'mgs') browseURL(png) ## End(Not run)
Makes a preamble for a LaTeX Document.
makePreamble( landscape = FALSE, wide = if (landscape) 279.4 else 215.9, long = if (landscape) 215.9 else 279.4, geoLeft = "1mm", geoRight = "1mm", geoTop = "1mm", geoBottom = "1mm", documentclass = command("documentclass", args = "article"), xcolorPackage = command("usepackage", options = list("dvipsnames", "svgnames", "table"), args = "xcolor"), geometryPackage = command("usepackage", options = list(left = geoLeft, top = geoTop, bottom = geoBottom, right = geoRight), args = "geometry"), geometry = command("geometry", args = list(paste0("papersize=", paste0("{", wide, "mm", ",", long, "mm}")))), multirow = command("usepackage", args = "multirow"), float = command("usepackage", args = "float"), longtable = command("usepackage", args = "longtable"), inputenc = command("usepackage", options = "utf8", args = "inputenc"), fontenc = command("usepackage", options = "T1", args = "fontenc"), morePreamble = NULL, ... )
makePreamble( landscape = FALSE, wide = if (landscape) 279.4 else 215.9, long = if (landscape) 215.9 else 279.4, geoLeft = "1mm", geoRight = "1mm", geoTop = "1mm", geoBottom = "1mm", documentclass = command("documentclass", args = "article"), xcolorPackage = command("usepackage", options = list("dvipsnames", "svgnames", "table"), args = "xcolor"), geometryPackage = command("usepackage", options = list(left = geoLeft, top = geoTop, bottom = geoBottom, right = geoRight), args = "geometry"), geometry = command("geometry", args = list(paste0("papersize=", paste0("{", wide, "mm", ",", long, "mm}")))), multirow = command("usepackage", args = "multirow"), float = command("usepackage", args = "float"), longtable = command("usepackage", args = "longtable"), inputenc = command("usepackage", options = "utf8", args = "inputenc"), fontenc = command("usepackage", options = "T1", args = "fontenc"), morePreamble = NULL, ... )
landscape |
if TRUE, default orientation is ‘landscape’ not ‘portrait’ |
wide |
page width in mm |
long |
page lenth in mm |
geoLeft |
geometry package: left margin |
geoRight |
geometry package: right margin |
geoTop |
geometry package: top margin |
geoBottom |
geometry package: bottom margin |
documentclass |
document class command |
xcolorPackage |
xcolor package command |
geometryPackage |
geometry package command |
geometry |
geometry specification |
multirow |
multirow specification |
float |
float specification |
longtable |
longtable specification |
inputenc |
input encoding |
fontenc |
output encoding |
morePreamble |
additional preamble before beginning the document |
... |
ignored |
character
makePreamble()
makePreamble()
Escapes LaTeX reserved characters. Generic, with default, character, and data.frame methods.
reserve(x, ...)
reserve(x, ...)
x |
object |
... |
passed arguments |
Other reserve:
reserve.character()
,
reserve.data.frame()
,
reserve.default()
,
reserve.factor()
,
reserve.list()
Escapes LaTeX reserved characters as suggested by https://en.wikibooks.org/wiki/LaTeX/Basics#Reserved_Characters.
## S3 method for class 'character' reserve( x, target = c("#", "$", "%", "^", "&", "_", "{", "}", "~", "\\"), replacement = c("\\#", "\\$", "\\%", "\\^{}", "\\&", "\\_", "\\{", "\\}", "\\~{}", "\\textbackslash{}"), ... )
## S3 method for class 'character' reserve( x, target = c("#", "$", "%", "^", "&", "_", "{", "}", "~", "\\"), replacement = c("\\#", "\\$", "\\%", "\\^{}", "\\&", "\\_", "\\{", "\\}", "\\~{}", "\\textbackslash{}"), ... )
x |
character |
target |
sequence to find (regular expression unless fixed is false) |
replacement |
sequence to use |
... |
passed arguments |
Other reserve:
reserve.data.frame()
,
reserve.default()
,
reserve.factor()
,
reserve.list()
,
reserve()
Applies reserve
to the columns of a data.frame.
## S3 method for class 'data.frame' reserve(x, ...)
## S3 method for class 'data.frame' reserve(x, ...)
x |
object |
... |
passed arguments |
Other reserve:
reserve.character()
,
reserve.default()
,
reserve.factor()
,
reserve.list()
,
reserve()
foo <- c('#','$%^','&_{','}~\\') bar <- data.frame( stringsAsFactors = FALSE, a = as.numeric(factor(foo)), b = foo, c = factor(foo) ) reserve(bar) # as.pdf(bar, wider = 10) # as.pdf(bar, target = '#') # fails
foo <- c('#','$%^','&_{','}~\\') bar <- data.frame( stringsAsFactors = FALSE, a = as.numeric(factor(foo)), b = foo, c = factor(foo) ) reserve(bar) # as.pdf(bar, wider = 10) # as.pdf(bar, target = '#') # fails
The default method returns its argument.
## Default S3 method: reserve(x, ...)
## Default S3 method: reserve(x, ...)
x |
object |
... |
passed arguments |
Other reserve:
reserve.character()
,
reserve.data.frame()
,
reserve.factor()
,
reserve.list()
,
reserve()
Coerces to character and escapes reserved characters.
## S3 method for class 'factor' reserve(x, ...)
## S3 method for class 'factor' reserve(x, ...)
x |
factor |
... |
passed arguments |
Other reserve:
reserve.character()
,
reserve.data.frame()
,
reserve.default()
,
reserve.list()
,
reserve()
Applies reserve
to the elements of a list.
## S3 method for class 'list' reserve(x, ...)
## S3 method for class 'list' reserve(x, ...)
x |
object |
... |
passed arguments |
Other reserve:
reserve.character()
,
reserve.data.frame()
,
reserve.default()
,
reserve.factor()
,
reserve()
Converts TEX to PDF. tex2pdf
accepts the file names of TEX fragments. It reads those fragments, wraps them like documents and makes PDF files.
tex2pdf(x, stem = NULL, dir = NULL, clean = TRUE, onefile = FALSE, ...)
tex2pdf(x, stem = NULL, dir = NULL, clean = TRUE, onefile = FALSE, ...)
x |
vector of file names |
stem |
the stem of a file name (no extension) |
dir |
output directory |
clean |
whether to delete system files after PDF creation |
onefile |
whether to combine TEX snippets into a single file |
... |
passed to |
invisible vector of paths to created files
## Not run: file <- file.path(tempdir(),'test.tex') writeLines(as.ltable(head(Theoph)), file) tex2pdf(file) ## End(Not run)
## Not run: file <- file.path(tempdir(),'test.tex') writeLines(as.ltable(head(Theoph)), file) tex2pdf(file) ## End(Not run)
Converts TEX to PNG. tex2png
accepts the file names of TEX fragments. It reads those fragments, wraps them like documents and makes PNG files (converted from PDF files).
tex2png( x, stem = NULL, dir = NULL, clean = TRUE, onefile = FALSE, replace = TRUE, ... )
tex2png( x, stem = NULL, dir = NULL, clean = TRUE, onefile = FALSE, replace = TRUE, ... )
x |
vector of file names |
stem |
the stem of a file name (no extension) |
dir |
output directory |
clean |
whether to delete system files after PNG creation |
onefile |
whether to combine tex snippets into a single file |
replace |
whether to delete the intermediate PDF files |
... |
passed to |
## Not run: file <- file.path(tempdir(),'test.tex') writeLines(as.ltable(head(Theoph)), file) tex2png(file, gs_cmd = 'mgs') ## End(Not run)
## Not run: file <- file.path(tempdir(),'test.tex') writeLines(as.ltable(head(Theoph)), file) tex2png(file, gs_cmd = 'mgs') ## End(Not run)
Renders and TEX files as PDF and opens them for viewing.
viewtex(x, delete = TRUE, latency = 1, png = FALSE, ...)
viewtex(x, delete = TRUE, latency = 1, png = FALSE, ...)
x |
vector of file names |
delete |
whether temporary pdf (_doc.pdf) should persist |
latency |
how many seconds to wait before deleting temporary PDF, |
png |
view as png instead of pdf |
... |
passed to |
file <- file.path(tempdir(),'test.tex') writeLines(as.ltable(head(Theoph)), file) ## Not run: viewtex(file) viewtex(file, png = TRUE, gs_cmd = 'mgs') ## End(Not run)
file <- file.path(tempdir(),'test.tex') writeLines(as.ltable(head(Theoph)), file) ## Not run: viewtex(file) viewtex(file, png = TRUE, gs_cmd = 'mgs') ## End(Not run)
Wrap text in a latex environment. x
is wrapped in the specified environment, with options and arguments formatted appropriately.
wrap(x, environment, options = NULL, args = NULL, depth = 0)
wrap(x, environment, options = NULL, args = NULL, depth = 0)
x |
character |
environment |
name of environment |
options |
list or vector |
args |
list or vector |
depth |
integer (extra spaces on the left) |
character
wrap('Hello','center')
wrap('Hello','center')