Post

1 follower Follow
0
Avatar

General questions on the use of sweave (VERY beginner in R Studio)

Hello,
I am very new in R and I heard about sweave.
I am trying to find out how it works, but since I am not "computer literate" and the resources out there presuppose some basic knowledge, I have a really hard time getting what I have to do to produce a sweave document.

First of all I am wondering how I "make" the sweave document. In the package manual it only gives how to format the text, how do I make the text in the first place?
I have made it through File->New->Sweave , but it does not contain the code of my .R file.
Do I have to copy-paste my .R input in the sweave file? Should this happen automatically with the creation of an .rnw?
Do I have to run commands in the .R file so that the sweave file will "find" my .R script automatically?
The best tutorial I could find (I got a general idea) was this http://lifeasclay.wordpress.com/2010/03/21/learning-r-using-sweave-on-a-os-x-10-6/ but it is on Macs. What about Windows or Linux?

And we continue. Let us imagine that I have produced the sweave file .rnw, what follows?
Do I open my .rnw file in LyX? Do I have to compile in .tex inside R Studio?

I saw here the use of Textmate with R http://www.youtube.com/watch?v=STLitSGLSzA this is exactly what I want to do, but in RStudio with LyX and not in Macs.
Anyone who has been able to use it?

P.S. I know that I shouldn't ask here about sweave, however, I have lost so much time reading tutorials and not getting much out of it, that even a short comment will help
Thank you for your time

Ian Pylvainen

Please sign in to leave a comment.

1 comment

0
Avatar

Unfortunately, as mentioned, this is not the best place to get help with Sweave. We do have some starter docs (if you haven't seen them - see the Sweave section):

http://www.rstudio.org/docs/

This explains how to insert code chunks via the menu, etc. Also you can either copy your R code into the code chunk (or build up the code from within the chunk itself) or you can source scripts in. Note that you'll need to put the full path to the file and that Sweave runs in a separate environment for reproducibility:

Note that for reproducibility purposes, this compile runs in a separate process and environment (rather than using the current workspace). This is to ensure the script will always produce the same result and not be effected by (or pollute) your regular R environment.

Finally, you can compile the .Rnw into a PDF from within RStudio. You should just use the "compile" PDF button for this. Also here a RStudio video I created for our 0.96 release that goes over various features with Sweave. It doesn't explicitly cover how to get started, but hopefully it shows enough of this as well as how to use some other helpful features:

http://vimeo.com/42130711

Also a basic example of working with Sweave which is a good introduction and the source code:

http://users.stat.umn.edu/~geyer/Sweave/foo.pdf
http://users.stat.umn.edu/~geyer/Sweave/foo.Rnw

Josh

Ian Pylvainen 0 votes