sweave

Extracting arguments of an R function to use in knitr

随声附和 提交于 2019-12-01 05:52:03
问题 Arguments of lm function can be obtained by using: args(lm) Output function (formula, data, subset, weights, na.action, method = "qr", model = TRUE, x = FALSE, y = FALSE, qr = TRUE, singular.ok = TRUE, contrasts = NULL, offset, ...) NULL Questions How to get: lm (formula, data, subset, weights, na.action, method = "qr", model = TRUE, x = FALSE, y = FALSE, qr = TRUE, singular.ok = TRUE, contrasts = NULL, offset, ...) with the description (Not complete help) of each Argument to be used in

R - adding page numbers to PDF

孤街浪徒 提交于 2019-12-01 05:46:37
问题 I'm having trouble adding page numbers to PDFs. Here's how I'm inserting pages / plots: pdf( file = pdfFilePath , width = 11 , height = 8.5 ) for ( ... ) { grid.newpage() pushViewport( viewport( layout = grid.layout( 2 , 2 ) ) ) ... print 4 plots .... } onefile seems to name a file by the page number, but I want the page numbers to appear in the same file. Edit I've modified @Gavin's code sample to produce a working version of mixing graphic types to get page numbers: require(ggplot2) pdf(

Silencing a package load message in Sweave

不打扰是莪最后的温柔 提交于 2019-12-01 02:59:54
问题 I'm loading optmatch in a Sweave document as follows: <<myCodeBlock, echo=FALSE>>= library(optmatch, quietly=TRUE) @ You're loading optmatch, by Ben Hansen, a package for flexible and optimal matching. Important license information: The optmatch package makes essential use of D. P. Bertsekas and P. Tseng's RELAX-IV algorithm and code, as well as Bertsekas' AUCTION algorithm and code. Bertsekas and Tseng freely permit their software to be used for research purposes, but non-research uses,

Appending % sign in output of prop.table

六月ゝ 毕业季﹏ 提交于 2019-12-01 02:33:33
问题 I'm trying to append % sign in the output of prop.table to use in Sweave . My attempted code is below: m <- matrix(1:4,2) dimnames(m) <- list(c("A", "B"), c("C", "D")) prop.table(m,1)*100 C D A 25.00000 75.00000 B 33.33333 66.66667 paste(round(prop.table(m,1)*100, 3), "%", sep = "") [1] "25%" "33.333%" "75%" "66.667%" paste(sprintf("%.1f", prop.table(m,1)*100), "%", sep = "") [1] "25.0%" "33.3%" "75.0%" "66.7%" Using paste will change the class from matrix to character. I'd highly appreciate

Change the size of ggplot2 plot in Sweave without making the text/numbers disproportionately large

怎甘沉沦 提交于 2019-12-01 01:37:30
I found this question about changing the size of a ggplot2 plot in Sweave. I added the Sweaveopts{width=3, height=3} and it does shrink the size of the plot, but it doesn't scale down the text. So in the end, all of the numbers on the axes overlap. Is there a way to scale the entire ggplot2 plot in Sweave so that I don't have to manually scale every component in the original ggplot2 call? It seems like something I should be able to do, but I can't find it in the ggplot2 book or on the website. Thanks! FWIW, here's my call in Sweave: \SweaveOpts{width=3, height=3} \begin{figure} \begin{center}

Making flattened pdfs in Sweave

[亡魂溺海] 提交于 2019-12-01 00:01:27
So I am creating pdfs using Sweave that include some graphs that have a ton of points on them. I can get the pdf well enough, but it seems to have created it with a ton of layers, so it's hard to open the file in Acrobat or Reader. When I do, I literally can watch the points load on the document. Is there a way to flatten the pdf in Sweave so that it's not so bulky? (Note that I am using RStudio. I know I should probably be using something else, but I haven't found anything that has worked this smoothly yet.) As Gavin said, there is no need to switch to knitr for this, though there are other

What is a null graphics device?

坚强是说给别人听的谎言 提交于 2019-11-30 19:06:16
I'm reading the R help page for ?devAskNewPage (it was linked from ?par...ask ). I can't understand what par(ask=F) / par(ask=T) does. What do I need to read about to understand this: If the current device is the null device, this will open a graphics device. ... The precise circumstances when the user will be asked to confirm a new page depend on the graphics subsystem. Obviously this needs to be an interactive session. In addition ‘recording’ needs to be in operation, so only when the display list is enabled (see ‘dev.control’) which it usually is only on a screen device. What are devices,

Displaying errors with sweave

烈酒焚心 提交于 2019-11-30 18:51:11
I'm writing some R notes with Sweave and would like to show common errors. For example, <<echo=TRUE, eval=TRUE>>= x = 5 #Case matters! x*X @ However when sweaving, the document won't compile due to the R error. Is there any way to make sweave compile and show the (nicely formated) error? As Shane suggests, use <<echo=TRUE,eval=FALSE>> for the code that will error, but you want to display, and then again with <<echo=FALSE,eval=TRUE,results=verbatim>> but with the same code wrapped in a try. There's an example here: http://tolstoy.newcastle.edu.au/R/help/05/09/11690.html This is a non-issue with

Split xtable ouput into sub tables

给你一囗甜甜゛ 提交于 2019-11-30 18:49:16
Have a question on using xtable with Sweave when there are multiple columns. A table I am working on has about 25 columns and 5 rows. The exact number of columns is not known as that is dynamic. When I run say, table1 <- table (df$someField) I get a table that essentially exceeds the page length. ColA ColB ColC --------------------------- RowA 1 2 3 ...... RowB 3 4 6 ...... If a do a xtable on this, and run it through Sweave, xtable(table1, caption="some table") it overflows. What I am looking for is something like, ColA ColB ColC --------------------------- RowA 1 2 3 RowB 3 4 6 ColD ColE

Making flattened pdfs in Sweave

左心房为你撑大大i 提交于 2019-11-30 18:10:51
问题 So I am creating pdfs using Sweave that include some graphs that have a ton of points on them. I can get the pdf well enough, but it seems to have created it with a ton of layers, so it's hard to open the file in Acrobat or Reader. When I do, I literally can watch the points load on the document. Is there a way to flatten the pdf in Sweave so that it's not so bulky? (Note that I am using RStudio. I know I should probably be using something else, but I haven't found anything that has worked