Learn R Programming

papeR (version 1.0-5)

toLatex: Cleaning R Code for printing in LaTeX environments

Description

The function produces code that LaTeX is able to typeset.

Usage

# S3 method for character
toLatex(object, ...)

# S3 method for sessionInfo toLatex(object, pkgs = NULL, locale = FALSE, base.pkgs = FALSE, other.pkgs = TRUE, namespace.pkgs = FALSE, citations = TRUE, citecommand = "\\citep", file = NULL, append = FALSE, ...)

Arguments

object

either an object of class character which should be cleaned for printing in LaTeX environments or an object of class sessionInfo.

pkgs

character vector (optional). Specify specific packages here to show information on these (instead of all attached packages). See package in sessionInfo.

locale

logical (default = FALSE). Show information on locale.

base.pkgs

logical (default = FALSE). Show information on base packages.

other.pkgs

logical (default = TRUE). Show information on currently attached packages. If pkgs is specified, information on these packages is given instead of all attached packages.

namespace.pkgs

logical (default = FALSE). Show information on packages whose namespaces are currently loaded but not attached.

citations

logical (default = TRUE). Should citations for all packages be added? BibTeX is used for storing the citations.

citecommand

Specify LaTeX-command for citation here. Curly brackets are added internally. Note that \ needs to be escaped, i.e., one needs to write \\ instead.

file

Specify path to BibTeX file where citations should be saved. If file = NULL is specified, the BibTeX entries are attached to the output as attribute "BibTeX". See examples for details.

append

logical (default = FALSE). Should citations be added to an existing BibTeX file (if existing) or should old BibTeX files be overwritten?

...

additional arguments. Currently not used.

Value

A character string with special markup is returned: The output is printed with LaTeX style syntax highlighting to be used e.g. in Sweave chunks with results=tex.

See Also

toLatex. For details on toLatex.sessionInfo see also sessionInfo.

Examples

Run this code
# NOT RUN {
txt <- "Price: <= 500$ & additional goodies"
toLatex(txt)

############################################################
## session info for automatic inclusion in reports

info <- toLatex(sessionInfo())
info

## extract first part (the Latex part)
toLatex(info)
## extract second part (the BibTeX part)
toBibtex(info)


############################################################
## usual usage scenario

## Do not run the following code automatically as it needs
## write access to the current working directory.
## This code (without removing the file) could for example
## be included in a LaTeX chunk of your Sweave or knitr
## report.

# }
# NOT RUN {
getwd()     ## location where write access is needed
toLatex(sessionInfo(), file = "packages.bib")
file.remove("packages.bib")
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab