sweave

More efficient R / Sweave / TeXShop work-flow?

谁说胖子不能爱 提交于 2019-12-02 14:32:14
I've now got everything to work properly on my Mac OS X 10.6 machine so that I can create decent looking LaTeX documents with Sweave that include snippets of R code, output, and LaTeX formatting together. Unfortunately, I feel like my work-flow is a bit clunky and inefficient: Using TextWrangler, I write LaTeX code and R code (surrounded by <<>>= above and @ below R code chunk) together in one .Rnw file. After saving changes, I call the .Rnw file from R using the Sweave command Sweave(file="/Users/mymachine/Documents/Assign4.Rnw", syntax="SweaveSyntaxNoweb") In response, R outputs the

Color Code Cells of xtable

流过昼夜 提交于 2019-12-02 12:09:39
问题 I've used R, sweave (but not knitr, and xtable, to create a table, where 1 column is an identifier, and the other three columns are "flag" columns that are either blank or contain a 1 (the flag). I want to be able to shad the last three columns so each cell is either green (if it is blank) or red (if it contains a 1). <<xtable3, results=tex>>= id <- c("1_1", "1_2", "2_1") a <- c(1,"","") b <- c("", 1, "") c <- c("", "", 1) d <- data.frame(id, a,b,c) dx <- xtable(d) align(dx) <- "|c|c|c|c|c|"

Color Code Cells of xtable

泄露秘密 提交于 2019-12-02 05:13:18
I've used R, sweave (but not knitr, and xtable, to create a table, where 1 column is an identifier, and the other three columns are "flag" columns that are either blank or contain a 1 (the flag). I want to be able to shad the last three columns so each cell is either green (if it is blank) or red (if it contains a 1). <<xtable3, results=tex>>= id <- c("1_1", "1_2", "2_1") a <- c(1,"","") b <- c("", 1, "") c <- c("", "", 1) d <- data.frame(id, a,b,c) dx <- xtable(d) align(dx) <- "|c|c|c|c|c|" print(dx, hline.after=-1:3) @ Edit: This is the output I get via Sumatra PDF Viewer: I have made

Table of multiple lm() models using apsrtable in Rmarkdown

早过忘川 提交于 2019-12-02 03:51:08
问题 Goal Present the results of multiple models, created using the lm() function, together in a nicely-formatted table. This table will be generated in a .Rmd file and output to a PDF document. Proposed Solution In Reproducible Research with R and RStudio , there is an example using the apsrtable() function to display multiple models side-by-side. This book provides the following code (p. 173-174): Code \begin{table} \caption{Example Nested Estimates Table with \emph{aprstable}} \label

Table of multiple lm() models using apsrtable in Rmarkdown

故事扮演 提交于 2019-12-02 01:16:27
Goal Present the results of multiple models, created using the lm() function, together in a nicely-formatted table. This table will be generated in a .Rmd file and output to a PDF document. Proposed Solution In Reproducible Research with R and RStudio , there is an example using the apsrtable() function to display multiple models side-by-side. This book provides the following code (p. 173-174): Code \begin{table} \caption{Example Nested Estimates Table with \emph{aprstable}} \label{BasicApsrTableExample} \begin{center} <<results= asis , echo=FALSE>>= # Load apsrtable package library(apsrtable)

If-Else Statement in knitr/Sweave using R variable as conditional

旧巷老猫 提交于 2019-12-02 00:07:20
问题 I am currently using knitr in R and RStudio to produce a LaTeX output. My code is a .Rnw file (called, say, testKnitr.Rnw) that is compiled to a pdf file with: knit("testKnitr.Rnw") // in RStudio pdflatex testKnitr.tex // in terminal I would like to use an if-else syntax in LaTeX so that, depending on the value of an R variable, one of two LaTeX text paragraphs are output. In these LaTeX paragraphs, I would like to use expressions like \Sexpr{} and and \ref. I have a minimal-working-example

Custom graphical device in Sweave

北慕城南 提交于 2019-12-01 19:29:22
My problem of inserting a pdf graphic with a special character in a Sweave document has been solved by creating the pdf plot outside Sweave itself and then importing it. Following the Sweave documentation, I have written a custom graphical device which should construct the pdf graphic exactly in the same way. However it doesn't work. Can you explain me why the second graphic of the Sweave document below does not work whereas it should be created exactly as the first one ? Am I wrong to believe it should ? \documentclass{article} \begin{document} \SweaveOpts{concordance=TRUE} <<setup, echo

Multiple plots in a for loop with Sweave

本小妞迷上赌 提交于 2019-12-01 17:51:57
My chunk in Sweave: <<fig=TRUE,echo=FALSE>>= for(i in 1:10) { plot(rep(i,10)) dev.new() } @ In the resulting pdf I get only one plot (from the first iteration). I would like to have all of the 10 plots printed. What am I doing wrong? I tried replacing dev.new() with frame() and plot.new() but nothing happened. Ben Bolker As @rawr suggests the easiest solution is to switch to knitr (there's really no reason at all not to!) and put fig.keep="all" in your code chunk options (if you switch to knitr you don't need fig=TRUE any more ... including figures works automatically, fig.keep="none" is the

Multiple plots in a for loop with Sweave

自闭症网瘾萝莉.ら 提交于 2019-12-01 16:59:45
问题 My chunk in Sweave: <<fig=TRUE,echo=FALSE>>= for(i in 1:10) { plot(rep(i,10)) dev.new() } @ In the resulting pdf I get only one plot (from the first iteration). I would like to have all of the 10 plots printed. What am I doing wrong? I tried replacing dev.new() with frame() and plot.new() but nothing happened. 回答1: As @rawr suggests the easiest solution is to switch to knitr (there's really no reason at all not to!) and put fig.keep="all" in your code chunk options (if you switch to knitr you

Dynamic references to figures in a R comment within Sweave document

≡放荡痞女 提交于 2019-12-01 11:31:20
I would like to find a way to use the LaTeX \ref{} markup to comment in the R code within a Sweave .Rnw file. Here are two examples, one in print http://cm.bell-labs.com/cm/ms/departments/sia/project/nlme/UGuide.pdf and one to use to work with: The .Rnw file % File: example.Rnw \documentclass{article} \usepackage{fullpage} \usepackage{graphics} \usepackage{Sweave} \usepackage[margin = 10pt, font=small, labelfont={bf}]{caption} \begin{document} Here is an example file to show what I want to do. I would like to figure out how to use the \LaTeX\ reference command to reference a figure being