LyX ⇒ including a Sweave/R code chunk in a LyX table cell
-
rrodriguezebiotic
- Posts: 2
- Joined: Sat May 08, 2010 9:23 pm
including a Sweave/R code chunk in a LyX table cell
I've successfully installed R 2.11.0 and LyX 1.6.5 in a MacBook Pro running Mac OS X 10.5.8. Some examples including more or less complex R code chunks run without a glitch.
But I am not able to include a R code chuck within a table.
This works:
% Preview source code for paragraph 10
<<Normal1,echo=T>>=
qs=1
@
But this doesn't work:
% Preview source code for paragraph 11
\begin{tabular}{|c|}
\hline
<<Normal1,echo=T>>=
pot=2
@
\tabularnewline
\hline
\end{tabular}
The LyX literate errors window gives this information:
*****
Errors:
LaTeX Error: Something's wrong--perhaps a missing \item.
LaTeX Error: Something's wrong--perhaps a missing \item.
LaTeX Error: Something's wrong--perhaps a missing \item.
LaTeX Error: Something's wrong--perhaps a missing \item.
Description:
\begin{Sinput}
Try typing <return> to proceed.
If that doesn't work, type X <return> to quit.
*****
Please, where am I wrong? Is it not possible to include code chunks in LyX tables?
Thanks for your help!
Ricardo
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
including a Sweave/R code chunk in a LyX table cell
I have no idea of what "R" is and I do not use LyX, but perhaps this could be helpful:
Code: Select all
\documentclass{article}
\begin{document}
\begin{tabular}{|c|}
\hline
\verb+<<Normal1,echo=T>>=+
\tabularnewline
\verb+pot=2+
\tabularnewline
\verb+@+
\tabularnewline
\hline
\end{tabular}
\end{document}-
rrodriguezebiotic
- Posts: 2
- Joined: Sat May 08, 2010 9:23 pm
including a Sweave/R code chunk in a LyX table cell
Your proposal avoids the error, but it doesn't get the code evaluated.
A brief explanation about the environment. R is a free software environment for statistical computing and graphics. See http://www.r-project.org/. Sweave (http://www.statistik.lmu.de/~leisch/Sweave/) is a R library that delivers results of data analysis to a LaTeX document. You can include R code in a LaTeX document (code chuncks) and what you get is the result of that code processed by R instead of the code itself. There are a number of Sweave options controlling this output.
As you know, while working in LyX, you can include ERTs floatings with LaTeX code. This is a convenient way of including LaTeX code in a LyX document.
Well, while dealing with R code chunks, ERT work fine when you are in the body of the document, but it doesn't work when you are within table. This is really a problem for me as we are using extensively tables to show results of a number of calculations.
By using your proposal, LyX is able to avoid the error, but the output doesn't include the result of the code: simply pot=2 as echo option is set to True.
It seems to me that the markers, <<>>= and @, for the code chunk does work outside a table, but they don't work within it!
Any idea will be welcome!!
Thanks!
-
tormod.boe
- Posts: 1
- Joined: Tue Jul 06, 2010 10:02 am
including a Sweave/R code chunk in a LyX table cell
Code: Select all
Sexpr{}Code: Select all
<<Normal1,echo=T>>=
qs=1
@Using
Code: Select all
\Sexpr{qs}Code: Select all
\begin{tabular}{|c|}
\hline
\Sexpr{qs}
\tabularnewline
\hline
\end{tabular}Good luck,
Tormod Bøe