Jay Kerns wrote a book titled "Introduction to Probability and Statistics Using R" or IPSUR for short. He has put up a web site for the book and Rcmdr plugin. There are at least two very important points from my side (I did not read the book, yet): 1. it is free to download (thank you Jay!!!) and 2. it was written with the help of LyX-Sweave. This shows that combination of LyX and Sweave is really powerful.
Showing posts with label LyX-Sweave. Show all posts
Showing posts with label LyX-Sweave. Show all posts
2010-07-28
2010-03-30
Update on "LyX and Sweave with R on Windows XP or Vista"
As previously Jeff contributed a not on how to setup LyX and Sweave on Win XP or Vista. See here for the note.
P.S. (2010-04-01) See also LyX Wiki
2010-02-09
LyX and Sweave with R on Windows XP or Vista
Jeff Laake contributed instructions on how to setup LyX to work with Sweave on Windows XP or Vista so that others might benefit. I did not read the instructions thorougly! He expanded the work of Murat. As far as I understand, in comparison to my approach they avoid the need for unix shell, which is nice!
P.S. (2010-04-01) See also LyX Wiki
2010-02-08
LyX-Sweave - use of Ctrl+Enter
Yihui writes:
I have been wondering if it is possible to use Enter instead of Ctrl+Enter in the Sweave code chunk in LyX. It is not quite convenient to press Ctrl+Enter, what's more, we are not able to copy R code and paste it into LyX from other editors (vice versa). I see we are allowed to use a single carriage return in LaTeX code embedded in LyX. Why must Sweave code use Ctrl+Enter? Thanks!My reply:
LyX prohibits the use of enter key for anything else than starting a new paragraph - this is default behaviour which is great for writing, but notorious for using Sweave with LyX. When you press enter you get a new paragraph, which would start a new chunk of code or is it new paragraph with default style - I do not remember the details at the moment. I agree that this is far from handy, but I was not able to find a solution for this. However, as you mention, it is possible to use ERT LaTeX boxes, to overcome this.
2010-01-29
LyX-Sweave on Ubuntu (Karmic)
Bret Collier sends the following install instructions for LyX-Sweave combination that worked for him on his Ubuntu (Karmic) setup.
Nothing was wrong with your instructions at http://www.bioconductor.org/CRAN/contrib/extra/lyx under install from what I can tell (other than where I put noweb.sty).
Here are the install steps I used (which basically follow the ones you provide on CRAN but I tried to list exactly what I did) to install Lyx 1.6.4 on my Linux Ubuntu Karmic Dual Core 32bit laptop with R v2.10.1 (2009-12-14). Note there are some minor differences with my install routine and what I found at- http://blog.nextbiomotif.com/2009/10/primer-to-sweave-with-lyx.html. Location of Sweave.sty is different.
1: I used Synaptic package manager to install Lyx and LaTex (tex-live). I updated R using sudo apt-get install and sudo apt-get install r-base before anything else.
2. Find the so-called LyX user directory or LyX library directory via the Help -> About LyX menu within LyX (mine was /usr/share/lyx/)
3. Save the 'preferences' file from CRAN (I saved unedited) into- /usr/share/lyx/
4. I saved all the literate-*.* files from CRAN to the layouts sub-directory of the Lyx user directory- /usr/share/lyx/layouts/
5. I put noweb.sty into- /usr/share/texmf/tex/latex/
6. I put Sweave.sty into- /usr/share/texmf/
7. I put any other .sty into- /usr/share/texmf/tex/latex/
8. I used texhash (or sudo texhash) to make sure all the .sty are located.
9. I made sure R was in the path (opened Terminal and typed in "R")
10. I used sudo lyx to open Lyx, then I went Tools->Reconfigure, got the reconfigure successful window, then I closed Lyx
11: Then I opened Lyx and everything was working on the Lyx end.
2009-11-12
Sweave-Lyx from terminal on Mac
Mark Heckmann writes:
# Find the lyx binary
$ which lyx
/usr/bin/lyx
# Start lyx from console
$ lyx&
In your paper "Using Sweave with Lyx" (great work bty) you pointed out that one can see the sweave error code when processing when starting lyx from the terminal. I just changed from Windows to Mac so that's new for me. Could you send me a few lines how to do that, that is how to operate lyx from terminal and sweave the content from the terminal.I am not familiar with Mac, though would be happy to own one;) Since Mac OS is build on top of some linux/unix like system you need to start the terminal (console) with shell and find the lyx binary. Perhaps something like this on my linux box (text following $ are shell commands)
# Find the lyx binary
$ which lyx
/usr/bin/lyx
# Start lyx from console
$ lyx&
2009-09-10
Changing font size of R output in Lyx Sweave
Is there a simple way of reducing the size of the font of the R output in Lyx/Sweave? It should be simple, but I can't get anything to work. Placing\huge or \tiny in front of code chunk doesn't change the output.
My reply:
The trick is in what Sweave actually does. Sweave replaces the R code with the code and results, but as Sinput and Soutput environments, i.e.,<<>Becomes>=
1 + 1
@\begin{Schunk}Therefore, I think you need to modify the Sinput and/or Soutput tex environments
\begin{Sinput}
> 1 + 1
\end{Sinput}
\begin{Soutput}
[1] 2
\end{Soutput}
\end{Schunk}
defined in the Sweave.sty file. However, I have never done anything like that. I think there are some R packages on CRAN that did some of this things - I remember seeing green output etc.
2009-07-16
LyX-Sweave: mandatory use of control+enter in code chunks
A user of LyX-Sweave is asking:
My embarrassingly simple question is this: For class notes, I often have lots of code to include. I develop code in R, & paste code into a scrap section. But then I have to step through it all and find the spots to insert control-enter to terminate lines. Inevitably I miss a few, then the code breaks (without a clue as to where). So, is there a simple way to move the code into a scrap that bypasses the control-enter problem?
First of all, you can easily see where Sweave has problem by launching LyX from the terminal. Then you will see the output of R CMD Sweave in the terminal and you can easily spot the problematic chunk. This works on MS Windows as well as on Linux! There is some development going on with LyX and it seems that it will be possible in the future to see the Sweave log in LyX directly as it is possible for LaTeX log.
I agree that mandatory the use of cotnrol+enter in scrap (code chunk) environment is suboptimal. I also hate it! But that is the way LyX is created. One way you can avoid this for now is to not use the "scrap" environment at all - you can insert the code chunks (starting with <<>>= and ending with @) in the LaTeX code (use shortcut control+l). I tried this on my laptop and works without problems. In future versions of LyX this resctriction might be lifted.
2009-04-01
Sweave.sh update
A local version of Sweave.sh has been updated:
- fixed a buglet that caused weaving the file twice when --weaver option was used --> this led to a change how caching is now invoked (--cache invokes cacheSweave package, while --cache --weaver or --weaver invokes weawer package)
- quoting *APP variables to ensure that things work in case of "bad" filenames, i.e., spaces in filenames etc.
- small changes in the documentation
I will take this opportunity to show how PDFAPP and PSAPP environmental variables can be used "open" options. This is an example from the help, which shows that these two variables need to be exported in order to have any effect. I am still fiddling whith how to provide any meaningfull defaults. My defaults are 'acroread' for PDF and 'gv' for Postscript, but I am happy to set any other more meaningfull defaults if there will be enough demand!
# Create PDF via the texi2dvi (latex) tool and open
# a produced file
Sweave.sh -otld file.Rnw
# Create PDF via the texi2dvi (latex) tool and open
# a produced file with a "non-standard" viewer
Sweave.sh -otld=acrobat file.Rnw
# ... or
export PDFAPP=acrobat
Sweave.sh -otld file.Rnw
This is an example of launcing Acrobat Reader installed on MS Windows, while Sweave.sh is launched within Cygwin X-terminal:
export PDFAPP=/cygdrive/c/Program\ Files/Adobe/Reader\ 9.0/Reader/AcroRd32.exe
Sweave.sh -otld file.Rnw
2008-12-19
2008-09-03
Using Beamer with LyX-Sweave
Dan Weeks (web1, web2) provided a solution on how to use Beamer with LyX & Sweave.
Make a literate-beamer layout file for LyX!
LyX then has a new Document Class that allows one to use the "scrap" style, and that portion of the text is sent to Sweave properly. However, there is a problem related with verbatim environment. Sweave makes a lot of use of verbatim environments, and beamer doesn't like those. You need to declare that a slide contains verbatim or you get errors. The reasonable solution is to add two ERT boxes in each slide that will contain "Sweave material". The ERT box at the beginning of the slide should contain
while the ERT box at the endo of the slide should contain
Make a literate-beamer layout file for LyX!
#% Do not delete the line below; configure depends on this
# \DeclareLaTeXClass[beamer, Sweave.sty]{beamer (beamer Sweave noweb)}
#
# This is a copy of literate-article.layout from LyX, but changed for
# Sweave - NoWeb syntax:
# - changed noweb.sty to Sweave.sty
# - moved preamble to literate-scrap.inc
Format 2
Input beamer.layout
Input literate-scrap.inc
LyX then has a new Document Class that allows one to use the "scrap" style, and that portion of the text is sent to Sweave properly. However, there is a problem related with verbatim environment. Sweave makes a lot of use of verbatim environments, and beamer doesn't like those. You need to declare that a slide contains verbatim or you get errors. The reasonable solution is to add two ERT boxes in each slide that will contain "Sweave material". The ERT box at the beginning of the slide should contain
\begin{frame}[containsverbatim]
\frametitle{Slide title}
while the ERT box at the endo of the slide should contain
\end{frame}
2008-07-12
Mixing Noweb and Sweave in LyX
Ed asked:
Is it possible to configure LyX so that I can create a literate article, book or report with either the "standard" LyX/NoWeb settings or the Sweave/R settings? I've spent a few hours trying to figure out how to doit, but everything I've tried only gives me one of the two options.
You want to mix Noweb and Sweave in the same file? No way, since the literate layout files (see http://cran.r-project.org/contrib/extra/lyx/) were modified for Sweave. You can also not use Noweb in one file and Sweave in another file without changing the literate layouts and preferences file.
2008-07-11
LyX-Sweave on MS Windows
Jay Kerns has recently notified me that for LyX-Sweave on MS Windows one needs to add the bin directory of R installation (say contrib/extra/lyx/) to the PATH system variable. He is right, since LyX can not find R binary otherwise. On MS Windows I always add R to PATH variable, since I often use R CMD check or other commands in MS Windows Command Tool - terminal. New version of INSTALL file will be updated with this information. Goosh, administration of Linux is getting better and better in comparison to MS Windows, at least for me.
2008-06-09
Using Sweave with LyX customisation script
Gabor suggested I should write a short batch file or R script which would copy the various files needed to use Sweave in LyX so that one does not need to actually do it onself. That would be nice, but there are several things that I should take care of:
- I would need to find the LyX user/library directory. I do not know how to get his information in scriptable manner.
- If the preference file already exists, I would have to append new content. That is easy, but in case some definitions are already used I would first need to parse the old version of prefences. That would not be so easy.
- I would need to write a Unix shell script for Unix like systems and a batch file for MS Windows. I am not sure about Mac OS-X - I think Unix shell script should work there out of the box.
I think I will leave this step to someone else. I actually hope, that LyX developers might find a way to provide automatic customisation if R is installed on the computer. Some ideas were given here. Additionally, Gabors' {Sweave,Stangle}.bat could be used instead of {Sweave,Stangle}.sh that are shipped with R.
2008-06-08
Using Sweave with LyX on MS Windows
Ian Holliday has informed me that my solution for using Sweave with LyX has additional requirement that I have not stated. Beside LyX & R (obviously) one needs also a variant of Unix shell. I have not realized this before since I usually use Linux, which always has installed a variant of Unix shell. Additionally, I always install a set of Unix tools (via Cygwin or MSYS) on my MS Windows boxes. Therefore, I could not realize that Unix shell is needed. However, I could have figured this requirement since R CMD Sweave and R CMD Stangle (commands that drive the weaving and the tangling process - this two commands are also inserted in LyXs' preferences file) use shell scripts Sweave.sh and Stangle.sh. I have provided additional info about this issue in INSTALL file. New version of the Rnews paper will appear soon.
2007-12-28
Using Sweave with LyX
It has been a while since I managed to configure LyX (a great "word processor") to work with Sweave (literate programming using LaTeX and R - wikipedia page). The paper describing the whole thing will probably be published in the next issue of Rnews. Since, I received some inquiries, I have created a temporary web page at Google with all the files needed for the configuration, ...
Happy LyX-ing with R!
2007-08-02
Computer Algebra System (CAS) in LyX via Ryacas
Subscribe to:
Posts (Atom)