Showing posts with label LyX. Show all posts
Showing posts with label LyX. Show all posts

2010-07-28

IPSUR book used LyX-Sweave

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.

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.

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!

#% 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

I have answered question on using Computer Algebra System (CAS) in LyX via Ryacas. You can see the answer here. In summary, LyX has a way to work with different CAS internally, but I have shown how to use Ryacas via Sweave in LyX. I sent yesterday a note on the latter to Rnews. Stay tuned!