# Is sweave seriusly this difficult to get started with ?

#### thedreamshaper

##### New Member
I am trying to get started with sweave but i am finding it annoyingly difficult, i gather that i should run a .Rnw file from R

for example
http://www.stat.uni-muenchen.de/~leisch/Sweave/example-1.Snw

But when i then try to run it from R using a comand like
Code:
Sweave("C:/Documents and Settings/Thor/Desktop/sw.Rnw")
i get a bunch of errors.

What am i doing wrong ?

Isnt it just easier to work around sweave by using stuff like xtable ?

Thanks
Thor

#### Dason

It's hard to help if you don't actually tell us what's wrong. Can you copy the output it gives?

#### thedreamshaper

##### New Member
Ofcourse

> Sweave("C:/Documents and Settings/Thor/Desktop/sw.Rnw")
Writing to file sw.tex
Processing code chunks with options ...
1 : echo term verbatim

Error: chunk 1
Error in library(ctest) : there is no package called 'ctest'
No new documents are produced

#### Dason

Well I think the error is pretty informative. You don't have the ctest library. And it doesn't look to me like there is a ctest library on CRAN. But looking at the rest of the document I don't know why you would need the ctest library so if you remove the library(ctest) line does it work?

#### TheEcologist

##### Global Moderator
Wow! ctest? where did you get that code from? ctest no longer exist, and has not existed for quite a while.

I had to dig into the previous release info of R, it appears to have been merged into the stats package back in version 1.9.0.... and even before that I see in the archives that ctest was automatically loaded at start-up from version 0.9!! That code you have is ancient!

Just do as Dason says and remove any ctest references.

#### thedreamshaper

##### New Member
Removing the ctest reference makes it run, but the tex output doesnt work and reports the error

Code:
LaTeX Error: File 'Sweave.sty' not found
Which makes sense since no such file exists anywhere, infact i cant even see it referenced in the Sweave code (in OP).

@TheEcologist i found it by google searching for minimum sweave examples to get started with (if any one has one that actually works that would be great)

http://www.statistik.lmu.de/~leisch/Sweave/

#### thedreamshaper

##### New Member
I think meaby what i am really needing is something more like just being able to write my R results to text files and then importing these into latex documents. This is pretty simple stuff from the LaTex part(using the import command), and since xtable generates some nice LaTex code i am pretty much there, however how do i write this to a text file ?

A code like

Code:
library("xtable")
tekst <- xtable(summary(data))
cat(tekst,file=paste("output_name"))
Doesnt work since cat wont write the output(tekst)

Thanks

#### Lazar

##### Phineas Packard
Removing the ctest reference makes it run, but the tex output doesnt work and reports the error

Code:
LaTeX Error: File 'Sweave.sty' not found
Which makes sense since no such file exists anywhere, infact i cant even see it referenced in the Sweave code (in OP).

@TheEcologist i found it by google searching for minimum sweave examples to get started with (if any one has one that actually works that would be great)

http://www.statistik.lmu.de/~leisch/Sweave/
This one is easy enough to solve. Just copy the sweave.sty file into the file where you have your Rnw file. Obviously you have to download it first. What you are trying to do at the moment is like trying to run a package in R without installing it.

Sweave is hard to get started with but it is worth it for accuracy and for a range of other reasons.

P.S. many LaTeX editors can be set up to install packages on the fly. Nevertheless, it can be a good idea to copy the relavent .sty files to your project folder.

Last edited:

#### bryangoodrich

##### Probably A Mammal
I had the same issue, and I put the .sty file that stored in your R directory in the right places, and still it didn't work. It may be my use of a portable LaTeX system.

#### Lazar

##### Phineas Packard
I think your issue is different because of the portable installation. I think the issue here (i.e. the OP) is trying to come to grips with R LaTeX and Sweave all at once. All three have there own little things that can drive you crazy when you first start. I started and gave up learning sweave three times before I finally got it.

P.S. Bryan are you also using LaTeX on a university computer. I had problems with this and had to manually configure LaTeX to access the internet.

#### bryangoodrich

##### Probably A Mammal
I think your issue is different because of the portable installation. I think the issue here (i.e. the OP) is trying to come to grips with R LaTeX and Sweave all at once. All three have there own little things that can drive you crazy when you first start. I started and gave up learning sweave three times before I finally got it.

P.S. Bryan are you also using LaTeX on a university computer. I had problems with this and had to manually configure LaTeX to access the internet.
No, I'm at work. It accesses the net fine. I've ran stuff to test that the LaTeX system works, and it manually downloaded stuff on-the-fly. I'll just have to get IT to install the full system for me.

#### thedreamshaper

##### New Member
Thanks for the help guys but i think i will avoid sweave, it is no difficult for me to get started with compared to any gains i might get at this point. For my masters or larger projects later on i will likely try to get something that will print the xtable output to .txt files and then just import them into Latex via the \input command. This also has the benefit of not forcing the compilation to run R code each time(im assuming it does so when it compiles) which ofcourse can take a very long time if i am doing simulations, so i would prefer it just took the newest output files and put into LaTex, ofcouse this means that i would also need to have a seperate file for the R code i want into my document, or just post it directly into LaTex.

#### Lazar

##### Phineas Packard
In passing, my typical approach is to get r to do the heavy lifting and then save the workspace. I then call the workspace in the Rnw file. This means you do not have to run the simulations over and over again.