Package 'lusweave'

Title: Sweave/Knitr Utilities
Description: Set of tools which simplify the usage of SWeave/Knitr in R and allow to easily create PDF files from within R.
Authors: Markus Bonsch [aut], Jan Philipp Dietrich [aut, cre], David Klein [aut], Florian Humpenoeder [aut]
Maintainer: Jan Philipp Dietrich <[email protected]>
License: BSD_2_clause + file LICENSE
Version: 1.46.3
Built: 2024-08-21 06:02:16 UTC
Source: https://github.com/pik-piam/lusweave

Help Index


lusweavedata

Description

General lusweave-dataset

Details

Pleasde do not directly acces that data. It should be only used by library functions.

Author(s)

Jan Philipp Dietrich


Close a swStream

Description

Function to create a pdf from a "swStream" object

Usage

swclose(
  stream,
  outfile = "",
  latexpath = "",
  clean_output = TRUE,
  engine = "knitr",
  save_stream = TRUE,
  knitquiet = TRUE
)

Arguments

stream

The swStream object to be processed.

outfile

Name of the pdf to be produced. Overwrites the name given in swopen

latexpath

Path of the LaTeX distribution (only necessary if not part of the PATH variable).

clean_output

If true, all auxiliary files will be deleted. If False, they remain, including each plot in its own pdf.

engine

Engine to use for conversion. Currently available: Sweave and knitr.

save_stream

If true (default) stream is saved to .rda file.

knitquiet

If false (default) progressbar and messages are printed otherwise suppressed.

Details

Creates a pdf with of the name specified in stream@name, with the content specified in stream@content, using [email protected] as the style file.

Value

No return value.

Author(s)

Markus Bonsch, David Klein

See Also

"swStream",swopen,swlatex,swR,swtable,swfigure

Examples

## Not run: 
test<-swopen(outfile="test.pdf")
swlatex(test,"tttteeeesssstttt")
swclose(test)
#Change the name
swclose(test,outfile="test_2.pdf")

## End(Not run)

swfigure

Description

Function to add R plots to a "swStream" object.

Usage

swfigure(
  stream,
  plot_func,
  ...,
  tex_caption = "",
  tex_label = "",
  fig.placement = "H",
  fig.width = "",
  fig.orientation = "portrait",
  sw_option = "",
  sw_label = "AUTO"
)

Arguments

stream

The swStream object to be modified.

plot_func

The R command, that produces the plot.

...

The arguments of the plotting command.

tex_caption

caption of the plot.

tex_label

label for the plot in .tex file for referencing.

fig.placement

Where to put the figure in the pdf. Typical LaTeX allocation like "h","ht","b" allowed.

fig.width

Width of the figure in the pdf as fraction of textwidth.

fig.orientation

landscape or portrait. If wrongly specified, parts of the figure will be cut (e.g. necessary for maps).

sw_option

Sweave options. See http://www.stat.uni-muenchen.de/~leisch/Sweave/Sweave-manual.pdf for details

sw_label

label for the plot in the Sweave file. (Not very likely necessary to be changed)

Details

Method designed to add an R plot to a swStream object, taking care that it is correctly embedded.

Value

No return value.

Author(s)

Markus Bonsch

See Also

"swStream",swopen,swclose,swlatex,swR,swtable

Examples

## Not run: 
test<-swopen(outfile="test.pdf")
swfigure(test,"plot",0,0,tex_caption="test figure",fig.width=0.5)
swclose(test)

## End(Not run)

swlatex

Description

Function to write LaTeX code to a "swStream" object.

Usage

swlatex(stream, ...)

Arguments

stream

The swStream object to be modified.

...

The content, that is to be added.

Details

Writes plain text to the swStream object. Be careful to escape R special characters like "\".

Value

No return value.

Author(s)

Markus Bonsch

See Also

"swStream",swopen,swclose,swR,swtable,swfigure

Examples

## Not run: 
test<-swopen(outfile="test.pdf")
swlatex(test,"This is a test text")
swclose(test)

## End(Not run)

Open an swStream

Description

Function to create a swStream object, that can be used to create a pdf including R output

Usage

swopen(
  outfile = "out.pdf",
  folder = "",
  template = "default",
  style = "default",
  orientation = NULL,
  envir = new.env()
)

Arguments

outfile

name for the output pdf. Can be specified with or w/o the .pdf extension. Can also contain a path to a differetn directory.

folder

Path where the output shall be produced.

template

A template which should be used for the PDF. Either a path to a .tex-file or a vector containing the tex template code or a name of a template which already comes with the library. Currently the following templates are part of the library: "default","default_landscape" and "david".

style

Style information which should be used for the PDF. Either a path to a .sty-file or a vector containing the tex style code or a name of a style which already comes with the library. Currently the following styles are part of the library: "default"

orientation

[DEPRECATED] Please do not use this argument. It is just left in the function for compatibility reasons.

envir

The environment in which the object should be saved. A new environment by default.

Value

An environment containing a "swStream" object named "stream" with a header for the Rnw file and the content of a stylefile.

Author(s)

Markus Bonsch, Jan Philipp Dietrich

See Also

"swStream",swclose,swlatex,swR,swtable,swfigure

Examples

## Not run: 
test<-swopen()
str(test)

testtwo<-swopen(outfile="test.pdf")
str(testtwo)


## End(Not run)

swR

Description

Function to write R code to a "swStream" object.

Usage

swR(stream, func, ..., option = "echo=FALSE")

Arguments

stream

The swStream object to be modified.

func

The R command, that shall be ecexuted. Can be specified as a string for back compatibility

...

Additional parameters passed to the function.

option

Formatting options.

Details

Method designed to write the output of R commands to a swStream object, taking care that it is correctly embedded. As func argument, you can pass either the function itself or its name as a string. User defined functions will only work with option one, two is only for back compatibility.

Value

No return value.

Author(s)

Markus Bonsch

See Also

"swStream",swopen,swclose,swlatex,swtable,swfigure

Examples

## Not run: 
test<-swopen(outfile="test.pdf")
swR(test,print,ls)
swR(test,print,"bla_blubb")
x<-c(1,2,3)
swR(test,print,paste(x,"bla"))
swclose(test)
# Only for back compatibility
swR(test,"print","bla_blubb")

## End(Not run)

Class "swStream" ~~~

Description

The swStream class provides an interface to the Sweave method and allows for easy creation of pdf's from R output.

Details

The Sweave method is an interface between R and LaTeX. It processes .Rnw files, that can contain LaTeX code as well as R code into proper .tex files, replacing the R commands by their output. See http://www.stat.uni-muenchen.de/~leisch/Sweave/ for details.
An additional style file is needed to compile the .tex file into a pdf.

Objects from the Class

Objects can be created by calls of the form new("swStream", name,folder, content, Sweave.sty, arguments, functions, auxfiles, envir).

Author(s)

Markus Bonsch

See Also

swopen,swclose,swlatex,swR,swtable,swfigure

Examples

## Not run: 
showClass("swStream")

## End(Not run)

swtable

Description

Function to add an R object to a "swStream" object.

Usage

swtable(
  stream,
  x,
  caption = NULL,
  label = NULL,
  transpose = FALSE,
  digits = NULL,
  vert.lines = 1,
  hor.lines = 1,
  align = "c",
  display = NULL,
  colsplit = NULL,
  ...
)

Arguments

stream

The swStream object to be modified.

x

An array or something that can be converted to an array, that shall be shown as a table. X should only contain 2 dimensions with more than 1 element, otherwise it cannot be plotted as a matrix.

caption

Description to be displayed in the pdf.

label

Label for the tex file for referencing.

transpose

Should the matrix be transposed before it is plotted?

digits

How many digits shall be shown for each number? Either one number or ncol()+1 numbers for each column seperately.

vert.lines

1 for vertical lines between the columns, 0 for no vertical lines. If you want lines only somewhere, set this to 0 and use align.

hor.lines

1 for horizontal lines between the rows, 0 for no horizontal lines. A vector of length equal to nrow(x)+2 (for line above first row also) with 1 and 0 indicates to put lines wherever a one is mentioned, ohters will stay without lines. A vector of numbers between -1 and "nrow(x)", inclusive, indicating the rows after which a horizontal line should appear.

align

Alignment of the table content. You can specify a single character: "c" for centered, "l" for left, "r" for right. If you want different alignments for different columns, specify a vector of length equal to the table columns plus one (for the row names) with the alignment for each column. If you want vertical lines only between some columns or around the table, set vert.lines to 0 and add "|" to the alignment vector, where you want to have vertical lines.

display

How shall the content be displayed? Use "d" (for integers), "f", "e", "E", "g", "G", "fg" (for reals), or "s" (for strings).

colsplit

Number of columns after which the table is split into two (Integer). Table will not be splitted up if set to NULL.

...

Further options passed to print.xtable.

Details

This method provides the possibility to display the content of an array-like object in a table. It has to be specified, which two dimensions should be shown by choosing them before the object is sent to the function. The method is built on the xtable method. The table is then created with the print.xtable method, that takes all kind of arguments like placement etc. See that manuals for more information

Value

No return value.

Author(s)

Markus Bonsch, Jan Philipp Dietrich

See Also

"swStream",swopen,swclose,swlatex,swR,swfigure

Examples

## Not run: 
sw <- swopen(outfile="test.pdf")
a <- array(1:45,c(5,2,3),dimnames=list(paste0("a",1:5),paste0("b",1:2),paste0("c",1:3)))
print(a)
swtable(sw, a[,,1], "test 1")
swtable(sw, a[,1,], "test 2")
swtable(sw, a[,1,], "transpose test", transpose=TRUE)
swtable(sw, a[,1,], "colsplit test", transpose=TRUE, colsplit=2)
swclose(sw)

## End(Not run)