From mboxrd@z Thu Jan 1 00:00:00 1970 From: Riccardo Romoli Subject: Re: org-babel export table from R to LaTeX Date: Wed, 15 Feb 2012 12:00:18 +0100 Message-ID: References: <87vcn99zv0.fsf@xtof-netbook.home> <874nutjpj9.fsf@xtof-netbook.home> <874nut2h4v.fsf@med.uni-goettingen.de> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=002354470790f708d704b8fe9d95 Return-path: Received: from eggs.gnu.org ([140.186.70.92]:57677) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RxcbD-000113-Uq for emacs-orgmode@gnu.org; Wed, 15 Feb 2012 06:00:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rxcb6-0006oc-AV for emacs-orgmode@gnu.org; Wed, 15 Feb 2012 06:00:35 -0500 Received: from mail-qw0-f48.google.com ([209.85.216.48]:39113) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rxcb6-0006oR-31 for emacs-orgmode@gnu.org; Wed, 15 Feb 2012 06:00:28 -0500 Received: by qauh8 with SMTP id h8so1016282qau.0 for ; Wed, 15 Feb 2012 03:00:18 -0800 (PST) In-Reply-To: <874nut2h4v.fsf@med.uni-goettingen.de> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Andreas Leha Cc: emacs-orgmode@gnu.org --002354470790f708d704b8fe9d95 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Thanks for your suggestion, I solved the problem using: #+headers: :results output latex #+begin_src R :session *R* :exports results ... print(xtable(summary(mypca))) #+end_src Regards Riccardo 2012/2/14 Andreas Leha > Christophe Pouzat writes: > > > Sorry, > > > > Checking foo.org > > ( > http://orgmode.org/w/?p=3Dworg.git;a=3Dblob_plain;f=3Dorg-contrib/babel/e= xamples/foo.org;hb=3DHEAD > ) > > I got the correct way to do it: > > > > #+begin_src R :results output latex :exports results > > library(xtable) > > xtable(foo, caption =3D "ANOVA Table", label =3D "tab:one", > > digits =3D c(0, 0, 2, 0, 2, 3, 3)) > > #+end_src > > > > Does it solve your problem? > > > > Christophe > > > > Riccardo Romoli writes: > > > >> If I set :export latex when I exports to LaTeX I have only the R code, > not the > >> table. > >> > >> Best > >> > >> 2012/2/14 Christophe Pouzat > >> > >> Riccardo Romoli writes: > >> > >> > Hi, I work with org-babel and R. > >> > In the R session I create a table that I have to export to LaTeX= . > >> > This is the code I use: > >> > > >> > #+headers: :results latex > >> > #+begin_src R :session *R* :exports results > >> > ..... > >> > print(xtable(summary(mypca))) > >> > #+end_src > >> > > >> > I do not understand why the exported table is delimited by "|": > >> > > >> > |% latex table generated in R 2.14.1 by xtable 1.6-0 package | > >> > | % Tue Feb 14 16:21:48 2012 | > >> > | \begin{table}[ht] | > >> > | \begin{center} | > >> > | \begin{tabular}{rrrrrrrrrrrrrrrrr} | > >> > | \hline | > >> > | & PC1 & PC2 & PC3 & PC4 & PC5 & PC6 & PC7 & PC8 & PC9 & > PC10 & > >> > PC11 & PC12 & PC13 & PC14 & PC15 & PC16 \\ | > >> > | \hline | > >> > | Standard deviation & 3.4693 & 2.8113 & 2.5561 & 2.2668 & > >> > 2.0015 & 1.9236 & 1.7287 & 1.6220 & 1.4288 & 1.3456 & > 1.2596 & > >> > 1.2195 & 1.1278 & 1.0778 & 0.8390 & 0.0000 \\ | > >> > | Proportion of Variance & 0.2188 & 0.1437 & 0.1188 & > 0.0934 & > >> > 0.0728 & 0.0673 & 0.0543 & 0.0478 & 0.0371 & 0.0329 & > 0.0289 & > >> > 0.0270 & 0.0231 & 0.0211 & 0.0128 & 0.0000 \\ | > >> > | Cumulative Proportion & 0.2188 & 0.3625 & 0.4813 & 0.574= 7 > & > >> > 0.6476 & 0.7149 & 0.7692 & 0.8170 & 0.8541 & 0.8871 & > 0.9159 & > >> > 0.9429 & 0.9661 & 0.9872 & 1.0000 & 1.0000 \\ | > >> > | \hline | > >> > | \end{tabular} | > >> > | \end{center} | > >> > | \end{table} | > >> > | | > >> > > >> > Should I change some headers settings?? > >> > > >> > Best > >> > > >> > >> Hi Riccardo, > >> > >> Try ":exports latex" instead of ":exports results" > >> > >> Christophe > >> -- > >> > >> Most people are not natural-born statisticians. Left to our own > >> devices we are not very good at picking out patterns from a sea of > >> noisy data. To put it another way, we are all too good at picking > out > >> non-existent patterns that happen to suit our purposes. > >> Bradley Efron & Robert Tibshirani (1993) An Introduction to the > Bootstrap > >> > >> -- > >> > >> Christophe Pouzat > >> MAP5 - Math=E9matiques Appliqu=E9es =E0 Paris 5 > >> CNRS UMR 8145 > >> 45, rue des Saints-P=E8res > >> 75006 PARIS > >> France > >> > >> tel: +33142863828 > >> mobile: +33662941034 > >> web: http://www.biomedicale.univ-paris5.fr/physcerv/C_Pouzat.html > >> > >> > > Hi Riccardo, > > additionally, if you do not want to get too tightly bound to LaTeX, check > out the ascii-package, e.g. > > #+begin_src R :results output org wrap :exports results > library(ascii) > > ## from the lm help page: > ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14) > trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69) > group <- gl(2,10,20, labels=3Dc("Ctl","Trt")) > weight <- c(ctl, trt) > lm.D9 <- lm(weight ~ group) > lm.D90 <- lm(weight ~ group - 1) # omitting intercept > > print(ascii(anova(lm.D9)), type=3D"org") > #+end_src > > > Cheers, > Andreas > > > --002354470790f708d704b8fe9d95 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Thanks for your suggestion, I solved the problem using:

#+headers: := results output latex
#+begin_src R :session *R* :exports results
...<= br> print(xtable(summary(mypca)))
#+end_src

Regards
Riccardo



2012/2/14 Andreas Leha <andreas.leha@med.uni-goettingen.de>
Christophe Pouzat <christophe.pouzat@gmai= l.com> writes:

> Sorry,
>
> Checking foo.org
> (http://orgmode.= org/w/?p=3Dworg.git;a=3Dblob_plain;f=3Dorg-contrib/babel/examples/foo.org;h= b=3DHEAD)
> I got the correct way to do it:
>
> #+begin_src R :results output latex :exports results
> =A0 library(xtable)
> =A0 xtable(foo, caption =3D "ANOVA Table", label =3D "t= ab:one",
> =A0 =A0 =A0 digits =3D c(0, 0, 2, 0, 2, 3, 3))
> #+end_src
>
> Does it solve your problem?
>
> Christophe
>
> Riccardo Romoli <ric.romoli@gmail.com> writes:
>
>> If I set :export latex when I exports to LaTeX I have only the R c= ode, not the
>> table.
>>
>> Best
>>
>> 2012/2/14 Christophe Pouzat <christophe.pouzat@gmail.com>
>>
>> =A0 =A0 Riccardo Romoli <ric.romoli@gmail.com> writes:
>>
>> =A0 =A0 > Hi, I work with org-babel and R.
>> =A0 =A0 > In the R session I create a table that I have to expo= rt to LaTeX.
>> =A0 =A0 > This is the code I use:
>> =A0 =A0 >
>> =A0 =A0 > #+headers: :results latex
>> =A0 =A0 > #+begin_src R :session *R* :exports results
>> =A0 =A0 > .....
>> =A0 =A0 > =A0 print(xtable(summary(mypca)))
>> =A0 =A0 > #+end_src
>> =A0 =A0 >
>> =A0 =A0 > I do not understand why the exported table is delimit= ed by "|":
>> =A0 =A0 >
>> =A0 =A0 > |% latex table generated in R 2.14.1 by xtable 1.6-0 = package |
>> =A0 =A0 > | % Tue Feb 14 16:21:48 2012 |
>> =A0 =A0 > | \begin{table}[ht] |
>> =A0 =A0 > =A0 | \begin{center} |
>> =A0 =A0 > =A0=A0=A0 | \begin{tabular}{rrrrrrrrrrrrrrrrr} |
>> =A0 =A0 > =A0=A0=A0=A0=A0 | \hline |
>> =A0 =A0 > =A0=A0=A0=A0=A0 | & PC1 & PC2 & PC3 &= PC4 & PC5 & PC6 & PC7 & PC8 & PC9 & PC10 &
>> =A0 =A0 > =A0=A0=A0=A0=A0 PC11 & PC12 & PC13 & PC14= & PC15 & PC16 \\ |
>> =A0 =A0 > =A0=A0=A0=A0=A0 | \hline |
>> =A0 =A0 > =A0=A0=A0=A0=A0 | Standard deviation & 3.4693 &am= p; 2.8113 & 2.5561 & 2.2668 &
>> =A0 =A0 > =A0=A0=A0=A0=A0 2.0015 & 1.9236 & 1.7287 &= ; 1.6220 & 1.4288 & 1.3456 & 1.2596 &
>> =A0 =A0 > =A0=A0=A0=A0=A0 1.2195 & 1.1278 & 1.0778 &= ; 0.8390 & 0.0000 \\ |
>> =A0 =A0 > =A0=A0=A0=A0=A0 | Proportion of Variance & 0.2188= & 0.1437 & 0.1188 & 0.0934 &
>> =A0 =A0 > =A0=A0=A0=A0=A0 0.0728 & 0.0673 & 0.0543 &= ; 0.0478 & 0.0371 & 0.0329 & 0.0289 &
>> =A0 =A0 > =A0=A0=A0=A0=A0 0.0270 & 0.0231 & 0.0211 &= ; 0.0128 & 0.0000 \\ |
>> =A0 =A0 > =A0=A0=A0=A0=A0 | Cumulative Proportion & 0.2188 = & 0.3625 & 0.4813 & 0.5747 &
>> =A0 =A0 > =A0=A0=A0=A0=A0 0.6476 & 0.7149 & 0.7692 &= ; 0.8170 & 0.8541 & 0.8871 & 0.9159 &
>> =A0 =A0 > =A0=A0=A0=A0=A0 0.9429 & 0.9661 & 0.9872 &= ; 1.0000 & 1.0000 \\ |
>> =A0 =A0 > =A0=A0=A0=A0=A0 | \hline |
>> =A0 =A0 > =A0=A0=A0=A0=A0 | \end{tabular} |
>> =A0 =A0 > =A0=A0=A0 | \end{center} |
>> =A0 =A0 > =A0 | \end{table} |
>> =A0 =A0 > | |
>> =A0 =A0 >
>> =A0 =A0 > Should I change some headers settings??
>> =A0 =A0 >
>> =A0 =A0 > Best
>> =A0 =A0 >
>>
>> =A0 =A0 Hi Riccardo,
>>
>> =A0 =A0 Try ":exports latex" instead of ":exports r= esults"
>>
>> =A0 =A0 Christophe
>> =A0 =A0 --
>>
>> =A0 =A0 Most people are not natural-born statisticians. Left to ou= r own
>> =A0 =A0 devices we are not very good at picking out patterns from = a sea of
>> =A0 =A0 noisy data. To put it another way, we are all too good at = picking out
>> =A0 =A0 non-existent patterns that happen to suit our purposes. >> =A0 =A0 Bradley Efron & Robert Tibshirani (1993) An Introducti= on to the Bootstrap
>>
>> =A0 =A0 --
>>
>> =A0 =A0 Christophe Pouzat
>> =A0 =A0 MAP5 - Math=E9matiques Appliqu=E9es =E0 Paris 5
>> =A0 =A0 CNRS UMR 8145
>> =A0 =A0 45, rue des Saints-P=E8res
>> =A0 =A0 75006 PARIS
>> =A0 =A0 France
>>
>> =A0 =A0 tel: +33142863828
>> =A0 =A0 mobile: +33662941034
>> =A0 =A0 web: http://www.biomedicale.univ-paris5.fr= /physcerv/C_Pouzat.html
>>
>>

Hi Riccardo,

additionally, if you do not want to get too tightly bound to LaTeX, check out the ascii-package, e.g.

#+begin_src R :results output org wrap :exports results
=A0library(ascii)

=A0## from the lm help page:
=A0ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
=A0trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
=A0group <- gl(2,10,20, labels=3Dc("Ctl","Trt")) =A0weight <- c(ctl, trt)
=A0lm.D9 <- lm(weight ~ group)
=A0lm.D90 <- lm(weight ~ group - 1) # omitting intercept

=A0print(ascii(anova(lm.D9)), type=3D"org")
#+end_src


Cheers,
Andreas



--002354470790f708d704b8fe9d95--