Sweave is a function in the statistical programming language R that enables integration of R code into LaTeX or LyX documents.

learn more… | top users | synonyms

21
votes
4answers
2k views

Dynamically count and return number of words in a section

I am writing a proposal for which it is required to give the number of words of the main section in the proposal itself. I found this answer on how I can get a word count on a LaTeX document: Is ...
19
votes
1answer
7k views

Getting Sweave code chunks to stay inside page margins?

Sometimes I get to make an R code chunk (in Sweave) which is longer then the margins of the page. Is there a way to force it to "go to the next line" once that happens? Here is a simple example of ...
12
votes
3answers
7k views

Using fancyhdr to create an image based header and footer

I'm trying to generate a latex report (via Sweave and R) where the header of the document is an image that covers everything (including the top/left/right page margin) and the footer covers everything ...
12
votes
4answers
667 views

Workflow in Sweave: Handling TeX errors

I've been using LaTeX and R for a few years now, but am only now bringing them together via Sweave. As I put the document together, I run my R code in its own session to verify that it works properly, ...
12
votes
2answers
4k views

Tables with multiple panels in LaTeX, R and Sweave

I would like to know what the accepted Sweave/R/LaTeX solution is for producing tables with "panels": multiple parts, which may or may not contain the same columns, combined into one table. The ...
9
votes
3answers
1k views

Include Sweave input as verbatim

How do I keep Sweave from compiling things in a verbatim environment? For example: \documentclass{article} \begin{document} \begin{verbatim} <<>>= 1+1 @ \end{verbatim} \end{document} ...
9
votes
1answer
1k views

how to colorize syntax using R + Sweave?

I'm writing a LaTeX document using Sweave (a Beamer presentation, really), which weaves R code and LaTeX. Is there a way to make my chunks of code and its output highlighted? I could use listings ...
9
votes
2answers
790 views

Building TeX file from knitr Rnw as child of larger parent TeX file to use R objects and output

Here's my general problem: I'm writing my dissertation using a LaTeX template (http://www.latextemplates.com/template/masters-doctoral-thesis). The template is a parent file with multiple chapters as ...
8
votes
3answers
3k views

LaTeX techniques and templates for writing a book [closed]

I am about to write a couple of books using LaTeX. I am fairly used to producing small LaTeX articles using Sweave and R, but I have never written a book using LaTeX and I am not conversant with the ...
8
votes
2answers
2k views

R, Sweave, Hmisc: pretty-print numbers

I'm creating a LaTeX tables based on a matrix in R using the 'latex' function of the Hmisc package. dat = matrix(c(1000, 100, 10000, 10000), 2) latex(dat, file='') This works (as expected) ...
8
votes
1answer
417 views

Having trouble with pgfSweave and tikzDevice

On Ben Bolker's advice I started using pgfSweave and tikzDevice. I'm struggling with getting R graphs into LaTeX. This is my code for pgfSweave Rnw file: \documentclass{article} \usepackage{tikz} ...
8
votes
5answers
1k views

How to get correct dimensions for a ggplot2 plot in beamer

I have a beamer presentation made with Sweave that I'm preparing and was wanting to place some ggplot2 graphs in but the aspect ratio does not seem to come out correct. This is what is in my Rnw ...
8
votes
1answer
844 views

Sweave generating invalid LaTeX

I've encountered a problem when I'm using Sweave to convert an .Rnw file into a .tex file. Sweave is replacing three options from hyperref's \hypersetup block with the value NA. This is the section ...
8
votes
2answers
225 views

What tools are there to make LaTeX more viable at work

I do data mining in R, Python and various object oriented languages. I like using LaTeX to present my results; either to myself (i.e. use them for result interpretation/analysis) or to send to ...
7
votes
1answer
241 views

Is it possible to get Sweave/knitr in RStudio to output the .tex file without typesetting it?

I would like to know if it is possible to tell Sweave or knitr in RStudio to create the .tex file without trying to typeset it. I want to be able to run my .Rnw file and produce a .tex file which I ...
7
votes
1answer
829 views

How to build Knitr document from the command line

I would like to compile a knitr document from the command line. With Sweave, the sequence R CMD Sweave my_sweave_file.Rnw latex my_sweave_file.tex latex my_sweave_file.tex dvips my_sweave_file.dvi ...
7
votes
0answers
339 views

Can I import existing .Rnw Sweave file into LyX? [closed]

I am trying to import an existing Sweave .Rnw file into LyX. I wonder whether LyX is capable of doing it? My LyX version is 2.02 and I can use its Sweave module with no problem. I find out it does ...
6
votes
4answers
2k views

Multiple Tables Sweave/Latex

I am very new to LaTeX and Sweave but am excited that it may make my life much simpler when combined with R. What I am looking to do: Create multiple crosstabs, most likely in a loop. As a result, ...
6
votes
1answer
2k views

Sweave, Beamer and ggplot2

There's literally nothing on the internet showing how these work in conjunction with one another. I would really appreciate even the simplest example of a Rnw document that you would run with Sweave() ...
6
votes
6answers
1k views

How to comment in an R-chunk?

I'm quite new to both R and LaTeX, but I'm trying to work with both, using Sweave. I know you can comment in R using # and in LaTeX by using %. However, when I write a #comment in an R-chunk (between ...
6
votes
1answer
317 views

Best way to display percentages in Sweave?

What is the best way to display percentages in Sweave? A simple example: The number 4 is \Sexpr{4 / 7} of 7. What is the best way to get the document to display: The number 4 is 57.1% of 7.
6
votes
1answer
2k views

side-by-side xtables in Sweave

I use xtable to manage my tables in Sweave like this <<label=tab1, echo = FALSE, results = tex>>= print(xtable(Table1)) @ <<label=tab2, echo = FALSE, results = tex>>= ...
6
votes
1answer
721 views

Passing a variable from TeX to R in Sweave

I know it is possible to use \Sexpr to pass information from an R chunk to LaTeX. For example, <<echo=F,results=hide>>= a = 7 @ 42 is the answer to 6 x \Sexpr{a} Is there an ...
6
votes
1answer
80 views

noalign and \include

I have reduced my code to the following lines: \documentclass[9pt,letterpaper,oneside]{amsart} \usepackage{graphicx} \usepackage[table, dvipsnames]{xcolor} \usepackage{longtable} ...
5
votes
1answer
572 views

Remove\begin{Schunk} \begin{Sinput}

I am using Sweave to produce my tex. In addition I use lstlisting to highlight the source code as below. \begin{lstlisting}[caption={Computation $\widehat Y_4$ and its ...
5
votes
2answers
176 views

What do Sweave/knitr offer that make doesn't?

I use LaTeX to write papers and R for data analysis and visualization, so I've been looking into Sweave and knitr. The Sweave website says: The purpose is to create dynamic reports, which can be ...
5
votes
2answers
353 views

How to label a code section in Sweave

I'm new to sweave and was wondering what is the appropriate way to label a code section. For example, if I have: <<echo= true>>= x<-5 y<-x+5 @ How would I get it to put a either ...
5
votes
2answers
984 views

How to prevent text generated with `Sweave` from running off the right margin?

I am using Sweave to generate output for some R analysis. Some of the code generates long lines that are run off the right margin when the .tex file is compiled. I have pasted an example Schunk ...
5
votes
1answer
269 views

Using Sweave and XeLaTeX

I'm doing a report that is heavy in R but also would like to use system fonts, so I was hoping to be able to use Sweave and XeLaTeX. My preferred tex editor is TexShop (Mac 10.7), but it seems to ...
5
votes
3answers
546 views

Sweave Multiple Chapters

I am writing a large Sweave document that will be broken up into many chapters with the final output being a large pdf of everything and an individual pdf for each chapter (with the same page and ...
5
votes
1answer
171 views

Why are \twoheadleftarrow and \leftarrow so different? [Sweave, listings]

I am wondering why the \twoheadleftarrow in the code below looks so much different from (worse than) the \leftarrow, although according to the LaTeX symbol list, the arrow heads should be of the same ...
5
votes
4answers
707 views

Auctex TOC with multifile document

I'm writing my PhD thesis with LaTeX-Sweave and I use EMACS with AucTex and ESS. I have a master file (master.tex) and some slave files and my question is about the use of the TOC in the slave files. ...
5
votes
1answer
323 views

Selectively suppress caption numbering when using xtable

I have a chunk of code which is producing table output using Xtable and I would like to suppress the table numbering. I know I can suppress numbering using \caption* outside of Xtable but I'm stumped ...
5
votes
1answer
178 views

How to check image exists or not?

I'm working on Sweave and using includegraphics for include image in report dynamically. Pseudocode: <<> for ( i to 100) # run loop 1 to 100 { ...
5
votes
1answer
445 views

How to input \Sexpr{ as verbatim in Sweave?

Building on my question here: Include Sweave input as verbatim Is there a way to include the term \Sexpr{ in the Sweave document as verbatim. For example, to write: R code can be evaluated inline ...
5
votes
1answer
1k views

How to sweave Matlab or Mathematica code into LaTeX.

There is a package called pgfsweave for R. It can sweave R code into a LaTeX document. I found we can gain some advantage from this method. The report document can reproduce. The font in figure ...
5
votes
1answer
49 views

How can I figure out which parameters are passed to xelatex by Rstudio?

I'm using Rstudio to create a nice pdf report using sweave and xelatex. I can process the sweave file in Rstudio, but I'm trying to wrap this into a script, so I need to figure out what parameters are ...
5
votes
1answer
131 views

Sweave Float environment over 2 pages

I have a bit of Sweave code as such: <<label = Example1, echo= true>>= //Bunch of R Code @ I've tried putting it in my own float environment like so \newfloat{rcode}{h!}{rcode} ...
5
votes
1answer
524 views

How to randomize content with examdesign package using Sweave

Forgive me in advance if this is a dumb question, or too specific to one package. I've been using examdesign to randomize the order of questions, but I also want to randomly generate the content. I've ...
5
votes
1answer
354 views

Including path diagram in Sweave

I use the following code to do sem analysis and draw path diagram with sem R package. library(sem) R.DHP <- readMoments(diag=FALSE, names=c('ROccAsp', 'REdAsp', 'FOccAsp', ...
4
votes
1answer
1k views

\SweaveInput{…} with UTF-8 encoding?

Some hack here. In ?RweaveLatex manual, I found only paragraph about encoding in UTF-8 but considering Windows users: The use of fancy quotes (see ‘sQuote’) can cause problems when setting R ...
4
votes
1answer
699 views

longtable misplaced noalign

Question Why am I getting multiple misplaced \noalign errors? Reproducible example \documentclass{scrartcl} \usepackage{longtable} \usepackage{booktabs} \begin{document} \section{Table test} ...
4
votes
1answer
822 views

Making LaTeX documents with Hebrew? (in Sweave + RStudio)

I would like to write in Hebrew in an .Rnw file, and use it with RStudio. Searching around, I found an example for using Hebrew in LaTeX in general: Numbers, punctuation and parenthesis reversed in ...
4
votes
1answer
1k views

FancyVerb error for Sweave output in Beamer

I'm having trouble including Sweave output in my Beamer file. Specifically, the Soutput environment is causing problems (it runs if I comment those lines out, but, of course, the table is not ...
4
votes
2answers
2k views

Integrate 'Sweave.sty' in the TeXLive 2010 search path (on Linux)

I'd like to add 'Sweave.sty' to my search-path, so that I don't need to copy 'Sweave.sty' to every Sweave-Document I create. I've located 'Sweave.sty' in '/usr/share/R/share/texmf/tex/latex'. I tried ...
4
votes
1answer
177 views

Repeating section with identical structure and different content

I would like to repeat identical subsection format with different contents. For example \documentclass{article} \usepackage{graphicx} \begin{document} \section{Intro} \subsection{A-text} ...
4
votes
1answer
271 views

Sweave + sciposter conflict prevents italics in title

After some fooling around, I have determined that when package Sweave is loaded, italics in the title of a sciposter document is ignored (though underline works). I don't know enough to read the ...
4
votes
1answer
2k views

Difference between \Sexpr and <<>>=

I am new to sweave and learning a lot. For the most part \Sexpr works well for simple variables and also calling R functions. But other times it will fail, I have found that I can get around this ...
4
votes
1answer
42 views

Turning off line-wrapping in auctex for smooth transition with ess in same file

I sometimes use auctex + ess for Sweave/knitr documents. Every time I switch from auctex to ess and vice versa, there is a pause/jolt while the auctex lines re-wrap themselves. Previously, I also ...
4
votes
1answer
78 views

inline knitr code that isn't a simple number

It is easy enough to do something like \Sexpr{1 + 1}. But how can I do \Sexpr{mymatrix} with mymatrix being a matrix object in R workspace? More generally, how can I print object that is more complex ...