emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: David Hajage <dhajage@gmail.com>
To: Eric Schulte <schulte.eric@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: Re: problem with babel and R
Date: Tue, 17 Aug 2010 16:41:09 +0200	[thread overview]
Message-ID: <AANLkTi=ec+7gjO+DF5fi20pwZJUd9eA6Qnmwe3zhWv7c@mail.gmail.com> (raw)
In-Reply-To: <87tymtnxzi.fsf@gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 9373 bytes --]

Thank you very much for your answer.

But when I run the following code directly into R, no extra lines is added
by the ascii function:
> library(ascii)
Le chargement a nécessité le package : proto
> options(asciiType = "org")
> ascii(head(esoph)) # no extra line
|   | agegp | alcgp     | tobgp    | ncases | ncontrols |
|---+-------+-----------+----------+--------+-----------|
| 1 | 25-34 | 0-39g/day | 0-9g/day | 0.00   | 40.00     |
| 2 | 25-34 | 0-39g/day | 10-19    | 0.00   | 10.00     |
| 3 | 25-34 | 0-39g/day | 20-29    | 0.00   | 6.00      |
| 4 | 25-34 | 0-39g/day | 30+      | 0.00   | 5.00      |
| 5 | 25-34 | 40-79     | 0-9g/day | 0.00   | 27.00     |
| 6 | 25-34 | 40-79     | 10-19    | 0.00   | 7.00      |

To see what hapens, I tried this:
--8<---------------cut here---------------start------------->8---
#+srcname: foo
#+begin_src R :session *R* :results output org replace
  library(ascii)
  options(asciiType = "org")
  head(esoph)
#+end_src

#+results: foo

  agegp     alcgp    tobgp ncases ncontrols
1 25-34 0-39g/day 0-9g/day      0        40
2 25-34 0-39g/day    10-19      0        10
3 25-34 0-39g/day    20-29      0         6
4 25-34 0-39g/day      30+      0         5
5 25-34     40-79 0-9g/day      0        27
6 25-34     40-79    10-19      0         7
--8<---------------cut here---------------end--------------->8---

The extra line is still there.

In fact, the solution was to run 'library(ascii)' in another source block.
When I run only this:

--8<---------------cut here---------------start------------->8---
#+begin_src R :session *R* :results output org replace
  ascii(head(esoph))
#+end_src

#+results: foo
|   | agegp | alcgp     |    tobgp | ncases | ncontrols |
|---+-------+-----------+----------+--------+-----------|
| 1 | 25-34 | 0-39g/day | 0-9g/day |   0.00 |     40.00 |
| 2 | 25-34 | 0-39g/day |    10-19 |   0.00 |     10.00 |
| 3 | 25-34 | 0-39g/day |    20-29 |   0.00 |      6.00 |
| 4 | 25-34 | 0-39g/day |      30+ |   0.00 |      5.00 |
| 5 | 25-34 | 40-79     | 0-9g/day |   0.00 |     27.00 |
| 6 | 25-34 | 40-79     |    10-19 |   0.00 |      7.00 |
--8<---------------cut here---------------end------------->8---

Everything is then OK.
I have no idea why "library(ascii)..." generates an extra empty line in the
results.

If I understand, the results is all the text directly under "#+results:",
until the first empty line. But what happens if the result contains empty
lines? Here an example with ascii and Hmisc package:

--8<---------------cut here---------------start------------->8---
> library(ascii)
> library(Hmisc)
> ascii(describe(esoph[, 1:3]))
#+CAPTION: esoph[, 1:3]
- 3 Variable
- 88 Observations

*agegp*
| n  | missing | unique |
| 88 | 0       | 6      |

|           | 25-34 | 35-44 | 45-54 | 55-64 | 65-74 | 75+ |
| Frequency | 15    | 15    | 16    | 16    | 15    | 11  |
| %         | 17    | 17    | 18    | 18    | 17    | 12  |

*alcgp*
| n  | missing | unique |
| 88 | 0       | 4      |

 0-39g/day (23, 26%), 40-79 (23, 26%), 80-119 (21, 24%), 120+ (21, 24%)

*tobgp*
| n  | missing | unique |
| 88 | 0       | 4      |

 0-9g/day (24, 27%), 10-19 (24, 27%), 20-29 (20, 23%), 30+ (20, 23%)
--8<---------------cut here---------------end--------------->8---

As you can see, describe() generate a description of my data, and ascii
generate org-mode markup as result. The result contains empty rows. Since
there is no special characters indicating the end of the results in babel,
replace option will not work in this case. Is there any workaround?

Of course, ascii is not usefull in this case, but it can coerce into
org-mode markup many other R objects (see my previous example and
http://orgmode.org/worg/org-contrib/babel/examples/ascii.php)

David


On Tue, Aug 17, 2010 at 15:57, Eric Schulte <schulte.eric@gmail.com> wrote:

> Hi David,
>
> It seems that the problem here is in the ascii package.  It is inserting
> an empty line at the beginning of your table, so that the table is not
> snugly sitting under the #+results foo tag, because of this the table
> isn't seen as results and is not replaced -- if you delete that space
> then re-run the code block you'll notice that the table is replaced.
>
> Org-mode is very capable of inserting tabular data into Org-mode
> documents without using the ascii package.  For example the following
> would be a more idiomatic example of using Org-mode to create a table
> from R code.
>
> --8<---------------cut here---------------start------------->8---
> #+begin_src R
>  numbers <- matrix(c(51,43,22,92,28,21,68,22,9),ncol=3,byrow=TRUE)
>  numbers
> #+end_src
>
> #+results:
> | 51 | 43 | 22 |
> | 92 | 28 | 21 |
> | 68 | 22 |  9 |
>
> #+begin_src R :colnames yes
>  numbers <- matrix(c(51,43,22,92,28,21,68,22,9),ncol=3,byrow=TRUE)
>  numbers
> #+end_src
>
> #+results:
> | V1 | V2 | V3 |
> |----+----+----|
> | 51 | 43 | 22 |
> | 92 | 28 | 21 |
> | 68 | 22 |  9 |
> --8<---------------cut here---------------end--------------->8---
>
> or applied to your example, the following code block should generate the
> desired results.
>
> --8<---------------cut here---------------start------------->8---
> #+srcname: foo
> #+begin_src R :session *R*
>   head(esoph)
> #+end_src
> --8<---------------cut here---------------end--------------->8---
>
> One last small note: the "replace" argument to :results is normally the
> default value, and doesn't need to be explicitly added (although I can
> see why you would have added it in this case since it wasn't working as
> expected).
>
> Cheers -- Eric
>
> David Hajage <dhajage@gmail.com> writes:
>
> > I tried the code with the last development version of org-mode:
> >
> > #+srcname: foo
> > #+begin_src R :session *R* :results output org replace
> >   library(ascii)
> >   options(asciiType = "org")
> >   ascii(head(esoph))
> > #+end_src
> >
> > #+results: foo
> >
> >  |   | agegp | alcgp     | tobgp    | ncases | ncontrols |
> > |---+-------+-----------+----------+--------+-----------|
> > | 1 | 25-34 | 0-39g/day | 0-9g/day | 0.00   | 40.00     |
> > | 2 | 25-34 | 0-39g/day | 10-19    | 0.00   | 10.00     |
> > | 3 | 25-34 | 0-39g/day | 20-29    | 0.00   | 6.00      |
> > | 4 | 25-34 | 0-39g/day | 30+      | 0.00   | 5.00      |
> > | 5 | 25-34 | 40-79     | 0-9g/day | 0.00   | 27.00     |
> > | 6 | 25-34 | 40-79     | 10-19    | 0.00   | 7.00      |
> >
> >  |   | agegp | alcgp     | tobgp    | ncases | ncontrols |
> > |---+-------+-----------+----------+--------+-----------|
> > | 1 | 25-34 | 0-39g/day | 0-9g/day | 0.00   | 40.00     |
> > | 2 | 25-34 | 0-39g/day | 10-19    | 0.00   | 10.00     |
> > | 3 | 25-34 | 0-39g/day | 20-29    | 0.00   | 6.00      |
> > | 4 | 25-34 | 0-39g/day | 30+      | 0.00   | 5.00      |
> > | 5 | 25-34 | 40-79     | 0-9g/day | 0.00   | 27.00     |
> > | 6 | 25-34 | 40-79     | 10-19    | 0.00   | 7.00      |
> >
> > There is no more ">", but an extra space.
> > But, the replace option doesn't work: results are still appended. I am
> not
> > an org-mode guru (far, far away), but I think this is because when output
> is
> > org, there is no indication about the "end" of the results.
> >
> > David
> >
> >
> > On Tue, Aug 17, 2010 at 10:17, David Hajage <dhajage@gmail.com> wrote:
> >
> >> Hello,
> >>
> >> I am trying to use babel with R. Here the code:
> >>
> >> #+srcname: foo
> >> #+begin_src R :session *R* :results output org replace
> >>   library(ascii)
> >>   options(asciiType = "org")
> >>   ascii(head(esoph))
> >> #+end_src
> >>
> >> #+results: foo
> >>
> >> > |   | agegp | alcgp     | tobgp    | ncases | ncontrols |
> >> |---+-------+-----------+----------+--------+-----------|
> >> | 1 | 25-34 | 0-39g/day | 0-9g/day | 0.00   | 40.00     |
> >> | 2 | 25-34 | 0-39g/day | 10-19    | 0.00   | 10.00     |
> >> | 3 | 25-34 | 0-39g/day | 20-29    | 0.00   | 6.00      |
> >> | 4 | 25-34 | 0-39g/day | 30+      | 0.00   | 5.00      |
> >> | 5 | 25-34 | 40-79     | 0-9g/day | 0.00   | 27.00     |
> >> | 6 | 25-34 | 40-79     | 10-19    | 0.00   | 7.00      |
> >>
> >> > |   | agegp | alcgp     | tobgp    | ncases | ncontrols |
> >> |---+-------+-----------+----------+--------+-----------|
> >> | 1 | 25-34 | 0-39g/day | 0-9g/day | 0.00   | 40.00     |
> >> | 2 | 25-34 | 0-39g/day | 10-19    | 0.00   | 10.00     |
> >> | 3 | 25-34 | 0-39g/day | 20-29    | 0.00   | 6.00      |
> >> | 4 | 25-34 | 0-39g/day | 30+      | 0.00   | 5.00      |
> >> | 5 | 25-34 | 40-79     | 0-9g/day | 0.00   | 27.00     |
> >> | 6 | 25-34 | 40-79     | 10-19    | 0.00   | 7.00      |
> >>
> >> With org-mode 7.01g in emacs 23, there is two problems:
> >>  - an extra ">" is added in the first line while output is "org"
> >>  - when I run the code twice, the new results is appended, while I have
> the
> >> option "replace".
> >>
> >> Is there any problem with my header?
> >>
> >> Thank you very much for your help.
> >> David
> >>
> > _______________________________________________
> > 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
>

[-- Attachment #1.2: Type: text/html, Size: 19052 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
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

  reply	other threads:[~2010-08-17 14:41 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-17  8:17 problem with babel and R David Hajage
2010-08-17 12:01 ` David Hajage
2010-08-17 13:57   ` Eric Schulte
2010-08-17 14:41     ` David Hajage [this message]
2010-08-17 15:15       ` Eric Schulte
2010-08-17 17:07         ` Tom Short
     [not found]       ` <1668ca$1pq4c@mail.curie.net>
2010-08-18  6:53         ` David Hajage
2010-08-18 22:13           ` Eric Schulte
2010-08-26 16:10             ` Eric Schulte
2010-08-26 20:20               ` David Hajage
2010-08-26 21:51                 ` David Hajage
2010-08-26 22:06                   ` David Hajage
2010-08-26 23:37                     ` Eric Schulte

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='AANLkTi=ec+7gjO+DF5fi20pwZJUd9eA6Qnmwe3zhWv7c@mail.gmail.com' \
    --to=dhajage@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=schulte.eric@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).