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-12-21 04:55:16 UTC |
Source: | https://github.com/pik-piam/lusweave |
General lusweave-dataset
Pleasde do not directly acces that data. It should be only used by library functions.
Jan Philipp Dietrich
Function to create a pdf from a "swStream"
object
swclose( stream, outfile = "", latexpath = "", clean_output = TRUE, engine = "knitr", save_stream = TRUE, knitquiet = TRUE )
swclose( stream, outfile = "", latexpath = "", clean_output = TRUE, engine = "knitr", save_stream = TRUE, knitquiet = TRUE )
stream |
The |
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. |
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.
No return value.
Markus Bonsch, David Klein
"swStream"
,swopen
,swlatex
,swR
,swtable
,swfigure
## Not run: test<-swopen(outfile="test.pdf") swlatex(test,"tttteeeesssstttt") swclose(test) #Change the name swclose(test,outfile="test_2.pdf") ## End(Not run)
## Not run: test<-swopen(outfile="test.pdf") swlatex(test,"tttteeeesssstttt") swclose(test) #Change the name swclose(test,outfile="test_2.pdf") ## End(Not run)
Function to add R plots to a "swStream"
object.
swfigure( stream, plot_func, ..., tex_caption = "", tex_label = "", fig.placement = "H", fig.width = "", fig.orientation = "portrait", sw_option = "", sw_label = "AUTO" )
swfigure( stream, plot_func, ..., tex_caption = "", tex_label = "", fig.placement = "H", fig.width = "", fig.orientation = "portrait", sw_option = "", sw_label = "AUTO" )
stream |
The |
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) |
Method designed to add an R plot to a swStream object, taking care that it is correctly embedded.
No return value.
Markus Bonsch
"swStream"
,swopen
,swclose
,swlatex
,swR
,swtable
## 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)
## 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)
Function to write LaTeX code to a "swStream"
object.
swlatex(stream, ...)
swlatex(stream, ...)
stream |
The |
... |
The content, that is to be added. |
Writes plain text to the swStream object. Be careful to escape R special characters like "\".
No return value.
Markus Bonsch
"swStream"
,swopen
,swclose
,swR
,swtable
,swfigure
## Not run: test<-swopen(outfile="test.pdf") swlatex(test,"This is a test text") swclose(test) ## End(Not run)
## Not run: test<-swopen(outfile="test.pdf") swlatex(test,"This is a test text") swclose(test) ## End(Not run)
Function to create a swStream object, that can be used to create a pdf including R output
swopen( outfile = "out.pdf", folder = "", template = "default", style = "default", orientation = NULL, envir = new.env() )
swopen( outfile = "out.pdf", folder = "", template = "default", style = "default", orientation = NULL, envir = new.env() )
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. |
An environment containing a "swStream"
object
named "stream" with a header for the Rnw file and the content of a
stylefile.
Markus Bonsch, Jan Philipp Dietrich
"swStream"
,swclose
,swlatex
,swR
,swtable
,swfigure
## Not run: test<-swopen() str(test) testtwo<-swopen(outfile="test.pdf") str(testtwo) ## End(Not run)
## Not run: test<-swopen() str(test) testtwo<-swopen(outfile="test.pdf") str(testtwo) ## End(Not run)
Function to write R code to a "swStream"
object.
swR(stream, func, ..., option = "echo=FALSE")
swR(stream, func, ..., option = "echo=FALSE")
stream |
The |
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. |
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.
No return value.
Markus Bonsch
"swStream"
,swopen
,swclose
,swlatex
,swtable
,swfigure
## 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)
## 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)
The swStream class provides an interface to the Sweave method and allows for easy creation of pdf's from R output.
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 can be created by calls of the form
new("swStream", name,folder, content, Sweave.sty, arguments,
functions, auxfiles, envir)
.
Markus Bonsch
swopen
,swclose
,swlatex
,swR
,swtable
,swfigure
## Not run: showClass("swStream") ## End(Not run)
## Not run: showClass("swStream") ## End(Not run)
Function to add an R object to a "swStream"
object.
swtable( stream, x, caption = NULL, label = NULL, transpose = FALSE, digits = NULL, vert.lines = 1, hor.lines = 1, align = "c", display = NULL, colsplit = NULL, ... )
swtable( stream, x, caption = NULL, label = NULL, transpose = FALSE, digits = NULL, vert.lines = 1, hor.lines = 1, align = "c", display = NULL, colsplit = NULL, ... )
stream |
The |
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. |
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
No return value.
Markus Bonsch, Jan Philipp Dietrich
"swStream"
,swopen
,swclose
,swlatex
,swR
,swfigure
## 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)
## 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)