From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Hajage Subject: Re: R code not producing expected results Date: Fri, 13 Aug 2010 10:19:30 +0200 Message-ID: <-6451506161962481008@unknownmsgid> References: <1668ca$1opjg@mail.curie.net> Mime-Version: 1.0 (iPhone Mail 8A306) Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Return-path: Received: from [140.186.70.92] (port=38620 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OjpjU-0007Xe-9O for emacs-orgmode@gnu.org; Fri, 13 Aug 2010 04:35:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OjpUP-0005Im-Gs for emacs-orgmode@gnu.org; Fri, 13 Aug 2010 04:19:47 -0400 Received: from mail-fx0-f41.google.com ([209.85.161.41]:64184) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OjpUP-0005Ia-5r for emacs-orgmode@gnu.org; Fri, 13 Aug 2010 04:19:45 -0400 Received: by fxm3 with SMTP id 3so1616112fxm.0 for ; Fri, 13 Aug 2010 01:19:43 -0700 (PDT) In-Reply-To: <1668ca$1opjg@mail.curie.net> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: "Charles C. Berry" Cc: "Blanchette, Marco" , "emacs-orgmode@gnu.org" I think you need to add 'results output org' to the header. Do not try to convert ascii objects into data.frame, ascii() just print several classes or R objects with org markup. Not all R objects are supported, see methods(ascii). Some examples here: http://orgmode.org/worg/org-contrib/babel/examples/ascii.php The source code here: http://repo.or.cz/w/Worg.git/blob_plain/HEAD:/org-contrib/babel/examples/as= cii.org Best David Le 13 ao=FBt 2010 =E0 08:57, "Charles C. Berry" a = =E9crit : > On Thu, 12 Aug 2010, Blanchette, Marco wrote: > >> Dear all, >> > >> Sorry if this is something totally obvious but I am learning to use > org-mode for my everyday work with R. I just installed the latest > stable release of org-mode (v7.01g) on top of GNU Emacs 23.1.50.1 > (x86_64-apple-darwin10.2.0, NS apple-appkit-1038.25). I also > installed the CRAN ascii package v0.7 on top of R v2.11.1. I am > currently working on a MacBook pro with Snow Leopard 10.6.4 > >> > >> Early on today, while reading the org-babel intro, I was able to run > the following example but somehow, later tonight, it started to > break and I spent the last few hours scratching my head to > understand what change and why it now suddenly break. Your help will > be greatly appreciated as I am discovering that org-mode in > collaboration with org-babel have great potential to help us create > more readable report of our daily analysis, as long as I can get > through these early hurdles. > > The code you say is "straight from ...org-babel-doc-R.php" is not quite. > > Note all the header args: > > #+begin_src R :results output code :session ascii > > Also note that ascii() does not return an object of class "matrix" or "da= ta.frame". Try str(ascii( < all the rest > )). > > With :results value (the default) you will get a different outcome as > you saw below. > > 'value' tries to be smart about what it does with .Last.value, but "ascii= " objects are a bit too tricky for it. > > 'output' on the other hand is pretty simple on the elisp side and relies = on R's print() to get the dispatch for the print method right. > > If you want to use ':results value' you will need to form a data.frame fr= om ascii() yourself, rather than rely on as.data.frame to find a method to = do the conversion. Or you will need to write a method for as.data.frame.asc= ii. > > HTH, > > Chuck > > >> >> Here is the org buffer that now breaks: >> >> * Two examples of R code that worked when I started the tutorial but sud= denly started to fail... >> >> ** some R code that should generate a nice table >> #+BEGIN_SRC R >> library(ascii) >> options(asciiType=3D"org") >> >> d <- as.data.frame(replicate(4,rnorm(100))) >> >> ascii(cor(d),include.rownames=3DT, include.colnames=3DT,header=3DT) >> #+END_SRC >> >> ** Some code straight from [[http://orgmode.org/worg/org-contrib/babel/l= anguages/org-babel-doc-R.php][org-babel]] >> #+BEGIN_SRC R >> library(ascii) >> options(asciiType=3D"org") >> ascii(summary(table(1:4, 1:4))) >> #+END_SRC >> >> >> With the following error recover from the *Org-Babel Error* buffer >> >> Loading required package: proto >> Error in as.data.frame.default(x[[i]], optional =3D TRUE) : >> cannot coerce class 'c("ascii", "proto", "environment")' into a data.fra= me >> Calls: write.table ... data.frame -> as.data.frame -> as.data.frame.defa= ult >> Execution halted >> >> Thanks for the helps. >> -- >> Marco Blanchette, Ph.D. >> Assistant Investigator >> Stowers Institute for Medical Research >> 1000 East 50th St. >> >> Kansas City, MO 64110 >> >> Tel: 816-926-4071 >> Cell: 816-726-8419 >> Fax: 816-926-2018 >> >> _______________________________________________ >> Emacs-orgmode mailing list >> Please use `Reply All' to send replies to the list. >> Emacs-orgmode@gnu.org >> http://lists.gnu.org/mailman/listinfo/emacs-orgmode >> > > Charles C. Berry (858) 534-2098 > Dept of Family/Preventive Medi= cine > E mailto:cberry@tajo.ucsd.edu UC San Diego > http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-090= 1 > > > > _______________________________________________ > Emacs-orgmode mailing list > Please use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode > > L'int=E9grit=E9 de ce message n'=E9tant pas assur=E9e sur Internet, l'Ins= titut Curie ne peut =EAtre tenu responsable de son contenu. > Si vous n'=EAtes pas destinataire de ce message confidentiel, merci de le= d=E9truire et d'avertir imm=E9diatement l'exp=E9diteur. > Afin de contribuer au respect de l'environnement, merci de n'imprimer ce = mail qu'en cas de n=E9cessit=E9.