You are here:
Vanderbilt Biostatistics Wiki
>
Main Web
>
Seminars
>
RClinic
>
SweaveLatex
(revision 10) (raw view)
Edit
Attach
---+ =Sweave= and =LaTeX= The following file are to help you start to learn and use both =Sweave= and =LaTeX=: * The =Sweave= Manual and _example_ .nw =Sweave= files used in the =Sweave= manual can be found [[http://www.ci.tuwien.ac.at/~leisch/Sweave/][here]]. * Not So Short Intro to =LaTeX= can be found [[http://www.ctan.org/tex-archive/info/lshort/english/lshort.pdf][here]]. * Some =Sweave= and =LaTeX= basics: [[%ATTACHURL%/ex.sweave.latex.nw][ex.sweave.latex.nw]] * Results of the =Sweave= and =LaTeX= basics: [[%ATTACHURL%/ex.sweave.latex.pdf][ex.sweave.latex.pdf]] * A [[SweaveTemplate][template]] in which everyone can edit their latest ideas * Useful =\usepackage= statements, modified title, and modified page numbering: [[%ATTACHURL%/Latex.template.nw][Latex.template.nw]] ---++ Some Helpful Tips: 1 You need to add a blank line (with no extra spaces) after the =\end{document}= expression if you get the following error from =Sweave=:<br> =Warning message:= <br> =incomplete final line found by readLines on `blah.nw'= 1 _Commenting_ in your =.nw= file: * Use =%= (percent) signs (the =LaTeX= comment symbol) to comment out lines of text and whole R code chunks (i.e., from the =<<>>== to the =@= headers). * Use =#= (number) signs (the R comment symbol) to comment out lines of R code _within_ an R code chunk (i.e., between the =<<>>== to the =@= headers). 1 To setup =Sweave= to run outside of R (i.e., from a konsole command prompt): * Open a Konsole window. * Change to the =~/bin= (i.e., =/home/scottt/bin=) directory: =cd ~\bin= * List the =~/bin= directory to see if a =Sweave= shell script is already present: =ls= * If =Sweave= is listed in the contents of the directory, open =Sweave= in a text editor (here I use =pico=): =pico Sweave= 1 If =Sweave= is not present, open a new file to be named =Sweave= in a text editor (again using =pico=): =pico Sweave= * If =Sweave= was already present, make sure the opened file contains the following two lines (make sure it matches exactly). If =Sweave= was not present, type the following lines in the text editor: <br> =#!/bin/sh= <br> =echo "library(tools) ; Sweave(\"$1.nw\")" | R --no-save --no-restore= <br> =rm -f Rplots.ps graphics/*.eps= * The last line of the above script assumes you have set up the graphics director as in the template and that you will be using =pdflatex= so you don't need to keep =eps= files * Exit =pico= by typing =Ctrl+X= to save the =Sweave= file (answer =Yes= to saving changes, and keep the name of the file as =Sweave=). * At the command prompt type the following to initiate =Sweave= as a shell script: =chmod +x= * Change your 'path' to include the =~/bin= directory. * Change to your 'home' directory: =cd ~= * Open your =.bashrc= (a hidden file) in a text editor: =pico .bashrc= * In the text editor, type a new line at the end of the file: =export PATH=$PATH:~/bin= * Exit =pico= by typing =Ctrl+X= to save your =.bashrc= file (answer =Yes= to saving changes, and keep the name of the file as =.bashrc=). 1 Converting Sweave files (Frank's 7/26/06 email): * Some of you have needed to give reports created using Sweave to collaborators so they can extract tables and other components into a manuscript. The best approach I've found is to use tth to convert from <nop>LaTeX to html. The resulting file can be opened in Word or viewed with a web browser, as long as all the graphics files are available. The following twiki page shows how to do this in linux ([[http://biostat.mc.vanderbilt.edu/SweaveConvert][click here]]). You can also view the output in a browser such as konqueror and copy and paste it into an <nop>OpenOffice document and save in a variety of formats including Word. 1 See the following [[%ATTACHURL%/RCitation.pdf][pdf file]] to learn how to incorporate the proper R citation into your =Sweave= documents. * The raw =.nw= file used to create the linked pdf file: [[%ATTACHURL%/RCitation.nw][RCitation.nw]]: * The needed =.bib= file to create and reference: [[%ATTACHURL%/Rbiblioref.bib][Rbiblioref.bib]] 1 The following code in an example of how to use an =upData()= function invocation to generate a long variable label that will automatically _wrap_ in the =LaTeX= version of a =summary.formula()= (with =reverse = TRUE=) table. The =strwrap()= function =width== argument will dictate how wide the label is. <highlight> x <- data.frame(var1 = sample(1:100, size = 250, replace = TRUE), group = sample(c("A", "B"), size = 250, replace = TRUE)) x <- upData(x, labels = c(var1 = paste(strwrap(paste("This is an extremely long and descriptive", "variable label that would normally run off the page.", "Our goal is to break this variable label over multiple lines so we won't have to", "truncate the variable label in any way."), width = 60), collapse = "\\\\"))) latex(summary(group ~ var1, method = "reverse", data = x, overall = TRUE, file = "", landscape = TRUE)) </highlight>
Edit
|
Attach
|
P
rint version
|
H
istory
:
r32
|
r11
<
r10
<
r9
<
r8
|
B
acklinks
|
V
iew topic
|
Edit WikiText
|
More topic actions...
Topic revision: r10 - 20 Jul 2007,
TheresaScott
Main
Department Home Page
Biostatistics Graduate Program
Vanderbilt University Medical Center
Main Web
Main Web Home
Search
Recent Changes
Changes
Topic list
Biostatistics Webs
Archive
Main
Sandbox
System
Register
|
Log In
Copyright © 2013-2022 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Vanderbilt Biostatistics Wiki?
Send feedback