Questions tagged [sweave]

Sweave is a system for combining S (or R) code with LaTeX in a single document.

Sweave is a system for combining (or ) code with in a single document. It is an implementation of Donald Knuth's concept. For new projects, consider using instead, which is faster and provides more flexibility.

The Sweave file contains normal LaTeX code with R code chunks in it using the following syntax:

<<option1=TRUE,option2=3>>=
R code here
@

Generating a pdf from a Sweave file (generally with a .Rnw extension in R) is a two stage process:

  1. Running Sweave on the Rnw file, which evaluates the code chunks and generates a tex file.
  2. Compile the resulting tex file using e.g. pdflatex.

Sweave offers easy integration of R code into any LaTeX document and makes easier.

584 questions
78
votes
5 answers

General guide for creating publication quality tables using R, Sweave, and LaTeX

There are a range of tools available for creating publication quality tables using R, Sweave, and LaTeX. In particular, there are helper functions like latex in the Hmisc package, and xtable in the xtable package. I've also often written my own code…
Jeromy Anglim
  • 33,939
  • 30
  • 115
  • 173
58
votes
4 answers

What is the knitr equivalent of `R CMD Sweave myfile.rnw`?

What is the command-line knitr equivalent of R CMD Sweave myfile.rnw?
Jeromy Anglim
  • 33,939
  • 30
  • 115
  • 173
39
votes
1 answer

Get rid of \addlinespace in kable

In a knitr/Sweave report, the kable function of knitr with the option booktabs=TRUE adds a \addlinespace each fifth line: P1 & A & 10 & 11.016181 & 110.16181 & 44.95101 & 269.9745\\ P1 & B & 10 & 8.592386 & 85.92386 & 35.06083 & 210.5743\\ P1 & A &…
Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225
30
votes
5 answers

Generating LaTeX output from R data frame

I am running R v2.14.1 on Ubuntu. I am writing a script that will generate a data frame, which represents a table of results. I would like to output this 'table' as a .tex file so that I can create an 'academic publication' quality table, for…
Homunculus Reticulli
  • 65,167
  • 81
  • 216
  • 341
30
votes
3 answers

How to avoid using round() in every \Sexpr{}?

Is there a way to avoid the function round() when using Sweave/knitr? It's really annoying to write round(,2) in every \Sexpr{}. I would like to have two decimal places through the whole document. Thanks for your help Macs
beginneR
  • 3,207
  • 5
  • 30
  • 52
29
votes
11 answers

Sweave for python

I've recently started using Sweave* for creating reports of analyses run with R, and am now looking to do the same with my python scripts. I've found references to embedding python in Sweave docs, but that seems like a bit of a hack. Has anyone…
pufferfish
  • 16,651
  • 15
  • 56
  • 65
28
votes
2 answers

Handling Latex backslashes in xtable

I have a table that includes the following column: mytable <- data.frame(beta_0 = c(1,2,3) What I want to do is output a table with a column header in latex markup, e.g. $\beta_0$ However, I can not seem to figure out how to output the "$\beta_0$"…
David LeBauer
  • 31,011
  • 31
  • 115
  • 189
28
votes
1 answer

Does pandoc support Synctex?

I've spent a week writing an R vignette using knitr, with input in R Markdown, and output in HTML. Previously all vignettes that I wrote were in Sweave with a PDF target. One of the things I miss is Synctex, which gives the ability to jump from the…
user2554330
  • 37,248
  • 4
  • 43
  • 90
24
votes
3 answers

Writing big documents with Sweave. Is it possible to do as with LaTeX?

I am just discovering Sweave and R. I have seen some examples of Sweave documents and have also started to write one or two on my own. I am impressed by the ability of doing computations in R and outputting results directly in a LaTeX document. Now…
yCalleecharan
  • 4,656
  • 11
  • 56
  • 86
24
votes
2 answers

Using xtable with R and Latex, math mode in column names?

I'm using xtable to compile tables from R automatically while compiling my TeX document. The question I have is how I get the variable names in the table (which in my case are the column names in a dataframe) to be in math mode. I have stored my…
hejseb
  • 2,064
  • 3
  • 18
  • 28
22
votes
4 answers

R + Org-mode: how to avoid naming plot files?

When I use Sweave with R, I can avoid explicitly naming the plot files by simply enclosing the plot commands within a code-chunk like <> ... @. The Sweave driver automatically generates numbered plot files like fig1.pdf, fig2.pdf,…
Prasad Chalasani
  • 19,912
  • 7
  • 51
  • 73
21
votes
2 answers

Can Sweave produce many pdfs automatically?

I analyze measurements from many cities (hundreds), and need to create separate reports per city (in Adobe pdf-format). My process is like this: First RStudio to prepare the data to be shown, saved in X.Rda. In X.Rnw (RStudio) I read X.Rda, select…
Chris
  • 2,256
  • 1
  • 19
  • 41
20
votes
6 answers

get filename and path of `source`d file

How can a sourced or Sweaved file find out its own path? Background: I work a lot with .R scripts or .Rnw files. My projects are organized in a directory structure, but the path of the project's base directory frequently varies between different…
cbeleites unhappy with SX
  • 13,717
  • 5
  • 45
  • 57
20
votes
1 answer

Including an image using roxygen documentation

Is it possible to include an image in documentation generated by roxygen? I have a number of functions that are essentially wrappers for ggplot() that I'd like to document by showing an example of the output.
Brandon Bertelsen
  • 43,807
  • 34
  • 160
  • 255
20
votes
11 answers

How to capture R text+image output into one file (html, doc, pdf etc)?

The task is to create a file (word, rtf, pdf, html, or whatever) that will capture the output of R (e.g: not the code that created the output), into that format (including text and images). The way of doing this should involve as little change to…
Tal Galili
  • 24,605
  • 44
  • 129
  • 187
1
2 3
38 39