* R code not producing expected results
@ 2010-08-13 4:32 Blanchette, Marco
2010-08-13 6:23 ` Thomas S. Dye
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Blanchette, Marco @ 2010-08-13 4:32 UTC (permalink / raw)
To: emacs-orgmode@gnu.org
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.
Here is the org buffer that now breaks:
* Two examples of R code that worked when I started the tutorial but suddenly started to fail...
** some R code that should generate a nice table
#+BEGIN_SRC R
library(ascii)
options(asciiType="org")
d <- as.data.frame(replicate(4,rnorm(100)))
ascii(cor(d),include.rownames=T, include.colnames=T,header=T)
#+END_SRC
** Some code straight from [[http://orgmode.org/worg/org-contrib/babel/languages/org-babel-doc-R.php][org-babel]]
#+BEGIN_SRC R
library(ascii)
options(asciiType="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 = TRUE) :
cannot coerce class 'c("ascii", "proto", "environment")' into a data.frame
Calls: write.table ... data.frame -> as.data.frame -> as.data.frame.default
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: R code not producing expected results
2010-08-13 4:32 R code not producing expected results Blanchette, Marco
@ 2010-08-13 6:23 ` Thomas S. Dye
2010-08-13 6:57 ` Charles C. Berry
[not found] ` <1668ca$1opjg@mail.curie.net>
2 siblings, 0 replies; 4+ messages in thread
From: Thomas S. Dye @ 2010-08-13 6:23 UTC (permalink / raw)
To: Blanchette, Marco; +Cc: emacs-orgmode@gnu.org
Aloha Marco,
Here is the code behind the Worg page:
#+begin_src R :results output org
library(ascii)
options(asciiType="org")
ascii(summary(table(1:4, 1:4)))
#+end_src
This works here.
The key seems to be the header argument :results output
#+BEGIN_SRC R :results output
library(ascii)
options(asciiType="org")
d <- as.data.frame(replicate(4,rnorm(100)))
ascii(cor(d),include.rownames=T, include.colnames=T,header=T)
#+END_SRC
#+results:
#+begin_example
Welcome to R!
|----+------+-------+-------+-------+
| | V1 | V2 | V3 | V4 |
|----+------+-------+-------+-------+
| V1 | 1.00 | 0.09 | 0.09 | 0.13 |
| V2 | 0.09 | 1.00 | -0.00 | -0.13 |
| V3 | 0.09 | -0.00 | 1.00 | 0.18 |
| V4 | 0.13 | -0.13 | 0.18 | 1.00 |
|----+------+-------+-------+-------+
#+end_example
With it added to your other example, it does indeed generate a nice
table.
I think you are absolutely right about org-mode's babel capabilities
helping with your R work. I can't imagine a better environment for
working in R.
Good luck with your work.
All the best,
Tom
On Aug 12, 2010, at 6:32 PM, 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.
>
> Here is the org buffer that now breaks:
>
> * Two examples of R code that worked when I started the tutorial but
> suddenly started to fail...
>
> ** some R code that should generate a nice table
> #+BEGIN_SRC R
> library(ascii)
> options(asciiType="org")
>
> d <- as.data.frame(replicate(4,rnorm(100)))
>
> ascii(cor(d),include.rownames=T, include.colnames=T,header=T)
> #+END_SRC
>
> ** Some code straight from [[http://orgmode.org/worg/org-contrib/babel/languages/org-babel-doc-R.php
> ][org-babel]]
> #+BEGIN_SRC R
> library(ascii)
> options(asciiType="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 = TRUE) :
> cannot coerce class 'c("ascii", "proto", "environment")' into a
> data.frame
> Calls: write.table ... data.frame -> as.data.frame ->
> as.data.frame.default
> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: R code not producing expected results
2010-08-13 4:32 R code not producing expected results Blanchette, Marco
2010-08-13 6:23 ` Thomas S. Dye
@ 2010-08-13 6:57 ` Charles C. Berry
[not found] ` <1668ca$1opjg@mail.curie.net>
2 siblings, 0 replies; 4+ messages in thread
From: Charles C. Berry @ 2010-08-13 6:57 UTC (permalink / raw)
To: Blanchette, Marco; +Cc: emacs-orgmode@gnu.org
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
"data.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
from 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.ascii.
HTH,
Chuck
>
> Here is the org buffer that now breaks:
>
> * Two examples of R code that worked when I started the tutorial but suddenly started to fail...
>
> ** some R code that should generate a nice table
> #+BEGIN_SRC R
> library(ascii)
> options(asciiType="org")
>
> d <- as.data.frame(replicate(4,rnorm(100)))
>
> ascii(cor(d),include.rownames=T, include.colnames=T,header=T)
> #+END_SRC
>
> ** Some code straight from [[http://orgmode.org/worg/org-contrib/babel/languages/org-babel-doc-R.php][org-babel]]
> #+BEGIN_SRC R
> library(ascii)
> options(asciiType="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 = TRUE) :
> cannot coerce class 'c("ascii", "proto", "environment")' into a data.frame
> Calls: write.table ... data.frame -> as.data.frame -> as.data.frame.default
> 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 Medicine
E mailto:cberry@tajo.ucsd.edu UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901
^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <1668ca$1opjg@mail.curie.net>]
* Re: R code not producing expected results
[not found] ` <1668ca$1opjg@mail.curie.net>
@ 2010-08-13 8:19 ` David Hajage
0 siblings, 0 replies; 4+ messages in thread
From: David Hajage @ 2010-08-13 8:19 UTC (permalink / raw)
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/ascii.org
Best
David
Le 13 août 2010 à 08:57, "Charles C. Berry" <cberry@tajo.ucsd.edu> a écrit :
> 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 "data.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 from 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.ascii.
>
> HTH,
>
> Chuck
>
>
>>
>> Here is the org buffer that now breaks:
>>
>> * Two examples of R code that worked when I started the tutorial but suddenly started to fail...
>>
>> ** some R code that should generate a nice table
>> #+BEGIN_SRC R
>> library(ascii)
>> options(asciiType="org")
>>
>> d <- as.data.frame(replicate(4,rnorm(100)))
>>
>> ascii(cor(d),include.rownames=T, include.colnames=T,header=T)
>> #+END_SRC
>>
>> ** Some code straight from [[http://orgmode.org/worg/org-contrib/babel/languages/org-babel-doc-R.php][org-babel]]
>> #+BEGIN_SRC R
>> library(ascii)
>> options(asciiType="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 = TRUE) :
>> cannot coerce class 'c("ascii", "proto", "environment")' into a data.frame
>> Calls: write.table ... data.frame -> as.data.frame -> as.data.frame.default
>> 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 Medicine
> E mailto:cberry@tajo.ucsd.edu UC San Diego
> http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901
>
>
>
> _______________________________________________
> 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égrité de ce message n'étant pas assurée sur Internet, l'Institut Curie ne peut être tenu responsable de son contenu.
> Si vous n'êtes pas destinataire de ce message confidentiel, merci de le détruire et d'avertir immédiatement l'expéditeur.
> Afin de contribuer au respect de l'environnement, merci de n'imprimer ce mail qu'en cas de nécessité.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-08-13 8:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-13 4:32 R code not producing expected results Blanchette, Marco
2010-08-13 6:23 ` Thomas S. Dye
2010-08-13 6:57 ` Charles C. Berry
[not found] ` <1668ca$1opjg@mail.curie.net>
2010-08-13 8:19 ` David Hajage
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).