Uncategorized

Sweave and LaTeX example – a semi-difficult example for GCE Students

Bundled up is an example of Latex and Sweave in a template format (Link). It is an
assignment we had in the old module concerning literature survey –
i.e. bibliometry. The zip-file contains everything necessary, but the sweave
file is in rough form, but contains both basic and more complicated Sweave
examples. Sweaving is an example of literate data analysis and I calculated
a bibliometric index or two. You may check my work. Some may say that this
is too complicated of an example for a beginner in Sweave, but it is in my
opinion in the middle and is already in a form, which is useful for writing
reports. The TeX template serves as a template for reports and the sweave
file shows one how it works in connection with R. I find it wonderful
because I can insert data frame etc. from R directly into a report among
many many other things. Many people find the inclusion of results tedious,
especially when analyses and results change, such as during a master’s
thesis, but sweaving makes it easy to insert and update research results, as
well as documenting analysis. I can only recommend it for anyone who is
serious about cutting edge research in ecology and the environmental
sciences.

Read the README.txt for instructions of a HOW-TO. If you need help, well… 😉

Short instructions for getting things to work:
1. Sweave the file
2. TeX the file
3. Run BibTeX
4. TeX the file
5. TeX the file again
Finito!

from R:

base <- "/D/Documents/GCE_WIKI/Uploaded_Files/example/" ## Change accordingly
dirbase <- file.path(base,"Assignment")
setwd(dirbase)
Sweave("Oney_Citavi_Assignment.rnw") ### This is called sweaving
## Stangle("Oney_Citavi_Assignment.rnw") ### to extract just the R-code
tools::texi2dvi("Oney_Citavi_Assignment.tex") ### Compile LaTeX file from R.

With Linux after sweaving:

pdftex Oney_Citavi_Assignment
bibtex Oney_Citavi_Assignment
pdftex Oney_Citavi_Assignment
pdftex Oney_Citavi_Assignment

With MikTeX after sweaving:
Use the GUI! (Or R…)

Cheers,
Brian Oney

Credits:
Roger Bivand for his Sweave template.
Todd Jobe for the ecology BibTeX style file
The R-community
The LaTeX Community

Share this

Leave a Reply

Your email address will not be published. Required fields are marked *