* Wrong results from R source block when returning a list
@ 2015-11-03 12:08 Rainer M Krug
2015-11-03 16:59 ` Charles C. Berry
0 siblings, 1 reply; 3+ messages in thread
From: Rainer M Krug @ 2015-11-03 12:08 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1465 bytes --]
Hi
The following code block returns a wrong table / list:
#+begin_src R :results value list
list(1:10, 1:5)
#+end_src
#+RESULTS:
- (1 1)
- (2 2)
- (3 3)
- (4 4)
- (5 5)
- (6 1)
- (7 2)
- (8 3)
- (9 4)
- (10 5)
The result is actually in R:
#+begin_src R :results output
list(1:10, 1:5)
#+end_src
#+RESULTS:
: [[1]]
: [1] 1 2 3 4 5 6 7 8 9 10
:
: [[2]]
: [1] 1 2 3 4 5
This is likely caused by the recycling rules in R, but it is actually
wrong in the org context:
The shown result is:
#+begin_src R :results table
list(1:10, 1:5)
#+end_src
#+RESULTS:
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
| 4 | 4 |
| 5 | 5 |
| 6 | 1 |
| 7 | 2 |
| 8 | 3 |
| 9 | 4 |
| 10 | 5 |
Whil;e I would expect:
#+RESULTS:
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
| 4 | 4 |
| 5 | 5 |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
I have no idea if this is a bug or wrong result due to incompatible
types (R list and org table)?
Is this mentioned in the manual?
Rainer
--
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany)
Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa
Tel : +33 - (0)9 53 10 27 44
Cell: +33 - (0)6 85 62 59 98
Fax : +33 - (0)9 58 10 27 44
Fax (D): +49 - (0)3 21 21 25 22 44
email: Rainer@krugs.de
Skype: RMkrug
PGP: 0x0F52F982
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 454 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Wrong results from R source block when returning a list
2015-11-03 12:08 Wrong results from R source block when returning a list Rainer M Krug
@ 2015-11-03 16:59 ` Charles C. Berry
2015-11-05 11:06 ` Rainer M Krug
0 siblings, 1 reply; 3+ messages in thread
From: Charles C. Berry @ 2015-11-03 16:59 UTC (permalink / raw)
To: Rainer M Krug; +Cc: emacs-orgmode
On Tue, 3 Nov 2015, Rainer M Krug wrote:
> Hi
>
> The following code block returns a wrong table / list:
>
>
> #+begin_src R :results value list
> list(1:10, 1:5)
> #+end_src
>
> #+RESULTS:
> - (1 1)
> - (2 2)
> - (3 3)
> - (4 4)
> - (5 5)
> - (6 1)
> - (7 2)
> - (8 3)
> - (9 4)
> - (10 5)
>
> The result is actually in R:
In particular in `org-babel-R-write-object-command' which uses
write.table() which uses as.data.frame() which dispatches to
as.data.frame.list() which calls data.frame() where the recycling occurs.
[snip]
> I have no idea if this is a bug or wrong result due to incompatible
> types (R list and org table)?
If you can't coerce a non-atomic R object to a data.frame and get a
pleasing result, you need to craft your own solution.
>
> Is this mentioned in the manual?
Not that I know of. A comment in `Results Types' in ob-doc-R -
http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-R.html#orgheadline6
- might be helpful.
Chuck
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Wrong results from R source block when returning a list
2015-11-03 16:59 ` Charles C. Berry
@ 2015-11-05 11:06 ` Rainer M Krug
0 siblings, 0 replies; 3+ messages in thread
From: Rainer M Krug @ 2015-11-05 11:06 UTC (permalink / raw)
To: Charles C. Berry; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1698 bytes --]
"Charles C. Berry" <ccberry@ucsd.edu> writes:
> On Tue, 3 Nov 2015, Rainer M Krug wrote:
>
>> Hi
>>
>> The following code block returns a wrong table / list:
>>
>>
>> #+begin_src R :results value list
>> list(1:10, 1:5)
>> #+end_src
>>
>> #+RESULTS:
>> - (1 1)
>> - (2 2)
>> - (3 3)
>> - (4 4)
>> - (5 5)
>> - (6 1)
>> - (7 2)
>> - (8 3)
>> - (9 4)
>> - (10 5)
>>
>> The result is actually in R:
>
>
> In particular in `org-babel-R-write-object-command' which uses
> write.table() which uses as.data.frame() which dispatches to
> as.data.frame.list() which calls data.frame() where the recycling
> occurs.
Thanks for this info - I thought something along these lines, but this
makes it clear why.
>
> [snip]
>
>> I have no idea if this is a bug or wrong result due to incompatible
>> types (R list and org table)?
>
> If you can't coerce a non-atomic R object to a data.frame and get a
> pleasing result, you need to craft your own solution.
Yup - I did it in R
>
>>
>> Is this mentioned in the manual?
>
> Not that I know of. A comment in `Results Types' in ob-doc-R -
>
> http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-R.html#orgheadline6
>
> - might be helpful.
Yes - thanks,
Rainer
>
> Chuck
--
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany)
Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa
Tel : +33 - (0)9 53 10 27 44
Cell: +33 - (0)6 85 62 59 98
Fax : +33 - (0)9 58 10 27 44
Fax (D): +49 - (0)3 21 21 25 22 44
email: Rainer@krugs.de
Skype: RMkrug
PGP: 0x0F52F982
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 454 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-11-05 11:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-03 12:08 Wrong results from R source block when returning a list Rainer M Krug
2015-11-03 16:59 ` Charles C. Berry
2015-11-05 11:06 ` Rainer M Krug
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.