From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Hajage Subject: Re: Re: problem with babel and R Date: Thu, 26 Aug 2010 23:51:45 +0200 Message-ID: References: <87tymtnxzi.fsf@gmail.com> <1668ca$1pq4c@mail.curie.net> <87d3tflgc3.fsf@gmail.com> <87k4ndjqxb.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============2092494195==" Return-path: Received: from [140.186.70.92] (port=45112 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OokMo-0002AD-UR for emacs-orgmode@gnu.org; Thu, 26 Aug 2010 17:52:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OokMh-0001R7-Uv for emacs-orgmode@gnu.org; Thu, 26 Aug 2010 17:52:14 -0400 Received: from mail-fx0-f41.google.com ([209.85.161.41]:43005) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OokMh-0001Qm-Dq for emacs-orgmode@gnu.org; Thu, 26 Aug 2010 17:52:07 -0400 Received: by fxm3 with SMTP id 3so1934635fxm.0 for ; Thu, 26 Aug 2010 14:52:06 -0700 (PDT) In-Reply-To: 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: Eric Schulte Cc: emacs-orgmode@gnu.org --===============2092494195== Content-Type: multipart/alternative; boundary=001485f7c3564d52fa048ec102a9 --001485f7c3564d52fa048ec102a9 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Oups, I forgot ob-org in my .emacs... OK, now, really sorry for this. David On Thu, Aug 26, 2010 at 22:20, David Hajage wrote: > I am so sorry to bother you again, but I must miss something. > > When I write: > > #+begin_src R :results output org :exports both > library(ascii) > options(asciiType =3D "org") > ascii(head(esoph)) > #+end_src > > The results is: > > #+results: > #+BEGIN_SRC org > | | 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 | > #+END_SRC > > OK, the result is surrounded by BEGIN_SRC org/END_SRC. But when I export > this, the results is exported as fontified org code. What should I do to > have this result interpreted as org markup? > David > > > > On Thu, Aug 26, 2010 at 18:10, Eric Schulte wrote= : > >> Hi, >> >> A fix to this issue has been pushed up to the repository. As can now be >> read in the documentation of the `org-babel-insert-result' function [1], >> there is now a subtle distinction between ":results org" and ":results >> raw", where ":results org" will wrap code block results in a "begin_src >> org" block. The block wrapper makes it possible for the entirety of the >> results to be located and removed by Babel upon code block >> re-evaluation. >> >> In addition a new ob-org.el file has been added providing support for >> evaluation of Org-mode blocks. With this new language support loaded >> the above technique becomes a working replacement for ":results raw" >> allowing the body of the org code block to be interpreted as inline >> org-mode text on export. This is done through some non-standard default >> header arguments described in the recent commit message (see [2]) >> >> Best -- Eric >> >> "Eric Schulte" writes: >> >> > Hi David, >> > >> > "#+end_results: foo" (or some derivative syntax) sounds like a good >> > idea, I'll add it to the Babel task list. >> > >> > Thanks -- Eric >> > >> > David Hajage writes: >> > >> >> OK, I understand that using ":results org", the results is not altere= d, >> >> there is no post processing. But I don't want a post processing, I >> would >> >> like a way to tell babel where is the begining *and the end* of the >> output >> >> produces by a particular R source block. I think an "#+end_results: >> foo" at >> >> the end of the output could do the job. Then, the option "replace" >> could >> >> work in all situation, even if a blank line is inserted somewhere in >> the org >> >> output. No? >> >> David >> >> >> >> >> >> On Tue, Aug 17, 2010 at 17:15, Eric Schulte >> wrote: >> >> >> >>> Hi David, >> >>> >> >>> David Hajage writes: >> >>> >> >>> > Thank you very much for your answer. >> >>> > >> >>> >> >>> My pleasure >> >>> >> >>> > >> >>> > 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=E9cessit=E9 le package : proto >> >>> >> options(asciiType =3D "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 | >> >>> > >> >>> >> >>> ah, my fault, this isn't an ascii issue. >> >>> >> >>> > >> >>> > In fact, the solution was to run 'library(ascii)' in another sourc= e >> >>> block. >> >>> > When I run only this: >> >>> > >> >>> >> >>> Thanks for pointing this out, I see what's happening now. >> >>> >> >>> The :results output header argument (see [1] for information on head= er >> >>> arguments) informs Org-mode to collect all of the output of the sour= ce >> >>> code block. This means that when library(ascii) is run, an empty li= ne >> >>> is collected and appended to the output. Removing the "output" head= er >> >>> argument should fix this issue. >> >>> >> >>> My I ask why you are using the ascii package for simple table output= ? >> >>> It seems to me that this would be much simpler using the pure Org-mo= de >> >>> solution I suggested in my previous email. >> >>> >> >>> > >> >>> > #+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 | >> >>> > >> >>> > Everything is then OK. >> >>> > I have no idea why "library(ascii)..." generates an extra empty li= ne >> 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 contain= s >> empty >> >>> > lines? Here an example with ascii and Hmisc package: >> >>> > >> >>> >> >>> This is not quite right, see [2] for a discussion of results handlin= g. >> >>> The "org" option to results is a special case in which no >> >>> post-processing of the results takes place, and the raw output is >> >>> inserted into the org-mode buffer. >> >>> >> >>> Under normal usage w/o this header argument, results are either >> tabular >> >>> or are textual. If tabular a single table can easily be recognized >> and >> >>> handled, if textual they are normally enclosed in a block (example, >> >>> html, latex, etc...), the block then allows for empty lines while >> still >> >>> making it clear where the results end. >> >>> >> >> >> >> >> >>> >> >>> > >> >>> >> 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= %) >> >>> > >> >>> > 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 i= n >> >>> babel, >> >>> > replace option will not work in this case. Is there any workaround= ? >> >>> > >> >>> >> >>> When using ":results org" there is no workaround, as the explicit >> >>> purpose of this setting is for your results to be inserted directly >> into >> >>> the Org-mode buffer w/o any interpretation or alteration. >> >>> >> >> >> >> >> >>> >> >>> In general I would recommend keeping a 1-to-1 mapping between code >> >>> blocks and result items, which should resolve this issue. >> >>> >> >>> > >> >>> > Of course, ascii is not usefull in this case, but it can coerce in= to >> >>> > org-mode markup many other R objects (see my previous example and >> >>> > http://orgmode.org/worg/org-contrib/babel/examples/ascii.php) >> >>> > >> >>> >> >>> I see, that answers my question from above. Thanks >> >>> >> >>> Hope this helps -- Eric >> >>> >> >>> > >> >>> > David >> >>> > >> >>> > >> >>> > On Tue, Aug 17, 2010 at 15:57, Eric Schulte > > >> >>> 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 i= s >> 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=3D3,byrow=3D= 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=3D3,byrow=3D= 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 normal= ly >> 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 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 =3D "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 appende= d. >> 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 >> >>> 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 =3D "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 "or= g" >> >>> >> >> - when I run the code twice, the new results is appended, whi= le >> 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 >> >>> >> >> >>> >> >>> Footnotes: >> >>> [1] http://orgmode.org/manual/Header-arguments.html#Header-argument= s >> >>> >> >>> [2] >> >>> >> http://orgmode.org/manual/Results-of-evaluation.html#Results-of-evaluati= on >> >>> >> >>> >> >>> L'int=E9grit=E9 de ce message n'=E9tant pas assur=E9e sur Internet, = l'Institut >> >>> 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'imprime= r >> ce >> >>> mail qu'en cas de n=E9cessit=E9. >> >>> >> >> Footnotes: >> [1] >> ,----[org-babel-insert-result] >> | org-babel-insert-result is a Lisp function in `ob.el'. >> | >> | (org-babel-insert-result RESULT &optional RESULT-PARAMS INFO HASH >> | INDENT LANG) >> | >> | Insert RESULT into the current buffer. >> | By default RESULT is inserted after the end of the >> | current source block. With optional argument RESULT-PARAMS >> | controls insertion of results in the org-mode file. >> | RESULT-PARAMS can take the following values... >> | >> | replace - (default option) insert results after the source block >> | replacing any previously inserted results >> | >> | silent -- no results are inserted >> | >> | file ---- the results are interpreted as a file path, and are >> | inserted into the buffer using the Org-mode file syntax >> | >> | raw ----- results are added directly to the org-mode file. This >> | is a good option if you code block will output org-mode >> | formatted text. >> | >> | org ----- this is the same as the 'raw' option >> | >> | html ---- results are added inside of a #+BEGIN_HTML block. This >> | is a good option if you code block will output html >> | formatted text. >> | >> | latex --- results are added inside of a #+BEGIN_LATEX block. >> | This is a good option if you code block will output >> | latex formatted text. >> | >> | code ---- the results are extracted in the syntax of the source >> | code of the language being evaluated and are added >> | inside of a #+BEGIN_SRC block with the source-code >> | language set appropriately. Note this relies on the >> | optional LANG argument. >> | >> | [back] >> `---- >> >> [2] >> ,---- >> | ob-org has two non-standard header arguments in that it exports it's >> | results by default and the result type defaults to raw, this ensures >> | that the body of a begin_src org block exports transparently. >> | >> | This is a breaking change in that if you are currently using org >> | code blocks to export org-fontified code you will have to set the >> | ":exports" header argument for org-mode blocks to "code" on a block, >> | file, language or system-wide basis. >> `---- >> > > --001485f7c3564d52fa048ec102a9 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Oups, I forgot ob-org in my .emacs... OK, now, really sorry for this.
David


On Thu, Aug 26, 2010 at 22:20, David Haj= age <dhajage@gmai= l.com> wrote:
I am so sorry to bother you again, but I must miss something.

When I write:

#+begin_src R :results ou= tput org :exports both
library(ascii)
options(asciiType =3D "org")
ascii(head(esoph))
#+end_src

= The results is:

#+results:
#+BEGIN_= SRC org
| =A0 | agegp | alcgp =A0 =A0 | tobgp = =A0 =A0| ncases | ncontrols |
|---+-------+-----------+----------+--------+-----------|
| = 1 | 25-34 | 0-39g/day | 0-9g/day | 0.00 =A0 | 40.00 =A0 =A0 |
| 2= | 25-34 | 0-39g/day | 10-19 =A0 =A0| 0.00 =A0 | 10.00 =A0 =A0 |
= | 3 | 25-34 | 0-39g/day | 20-29 =A0 =A0| 0.00 =A0 | 6.00 =A0 =A0 =A0|
| 4 | 25-34 | 0-39g/day | 30+ =A0 =A0 =A0| 0.00 =A0 | 5.00 =A0 =A0 =A0= |
| 5 | 25-34 | 40-79 =A0 =A0 | 0-9g/day | 0.00 =A0 | 27.00 =A0 = =A0 |
| 6 | 25-34 | 40-79 =A0 =A0 | 10-19 =A0 =A0| 0.00 =A0 | 7.0= 0 =A0 =A0 =A0|
#+END_SRC

OK, the result is surrounded by BEGIN_SRC org/END= _SRC. But when I export this, the results is exported as fontified org code= . What should I do to have this result interpreted as org markup?
David



On Thu, Aug 26, 2010 at 18:10, Eric Schu= lte <schulte.eric@gmail.com> wrote:
Hi,

A fix to this issue has been pushed up to the repository. =A0As can now be<= br> read in the documentation of the `org-babel-insert-result' function [1]= ,
there is now a subtle distinction between ":results org" and &quo= t;:results
raw", where ":results org" will wrap code block results in a= "begin_src
org" block. =A0The block wrapper makes it possible for the entirety of= the
results to be located and removed by Babel upon code block
re-evaluation.

In addition a new ob-org.el file has been added providing support for
evaluation of Org-mode blocks. =A0With this new language support loaded
the above technique becomes a working replacement for ":results raw&qu= ot;
allowing the body of the org code block to be interpreted as inline
org-mode text on export. =A0This is done through some non-standard default<= br> header arguments described in the recent commit message (see [2])

Best -- Eric

"Eric Schulte" <schulte.eric@gmail.com> writes:

> Hi David,
>
> "#+end_results: foo" (or some derivative syntax) sounds like= a good
> idea, I'll add it to the Babel task list.
>
> Thanks -- Eric
>
> David Hajage <dhajage@gmail.com> writes:
>
>> OK, I understand that using ":results org", the results = is not altered,
>> there is no post processing. But I don't want a post processin= g, I would
>> like a way to tell babel where is the begining *and the end* of th= e output
>> produces by a particular R source block. I think an "#+end_re= sults: foo" at
>> the end of the output could do the job. Then, the option "rep= lace" could
>> work in all situation, even if a blank line is inserted somewhere = in the org
>> output. No?
>> David
>>
>>
>> On Tue, Aug 17, 2010 at 17:15, Eric Schulte <schulte.eric@gmail.com> wr= ote:
>>
>>> Hi David,
>>>
>>> David Hajage <dhajage@gmail.com> writes:
>>>
>>> > Thank you very much for your answer.
>>> >
>>>
>>> My pleasure
>>>
>>> >
>>> > But when I run the following code directly into R, no ext= ra lines is
>>> >added
>>> > by the ascii function:
>>> >> library(ascii)
>>> > Le chargement a n=E9cessit=E9 le package : proto
>>> >> options(asciiType =3D "org")
>>> >> ascii(head(esoph)) # no extra line
>>> > | =A0 | agegp | alcgp =A0 =A0 | tobgp =A0 =A0| ncases | n= controls |
>>> > |---+-------+-----------+----------+--------+-----------|=
>>> > | 1 | 25-34 | 0-39g/day | 0-9g/day | 0.00 =A0 | 40.00 =A0= =A0 |
>>> > | 2 | 25-34 | 0-39g/day | 10-19 =A0 =A0| 0.00 =A0 | 10.00= =A0 =A0 |
>>> > | 3 | 25-34 | 0-39g/day | 20-29 =A0 =A0| 0.00 =A0 | 6.00 = =A0 =A0 =A0|
>>> > | 4 | 25-34 | 0-39g/day | 30+ =A0 =A0 =A0| 0.00 =A0 | 5.0= 0 =A0 =A0 =A0|
>>> > | 5 | 25-34 | 40-79 =A0 =A0 | 0-9g/day | 0.00 =A0 | 27.00= =A0 =A0 |
>>> > | 6 | 25-34 | 40-79 =A0 =A0 | 10-19 =A0 =A0| 0.00 =A0 | 7= .00 =A0 =A0 =A0|
>>> >
>>>
>>> ah, my fault, this isn't an ascii issue.
>>>
>>> >
>>> > In fact, the solution was to run 'library(ascii)'= in another source
>>> block.
>>> > When I run only this:
>>> >
>>>
>>> Thanks for pointing this out, I see what's happening now.<= br> >>>
>>> The :results output header argument (see [1] for information o= n header
>>> arguments) informs Org-mode to collect all of the output of th= e source
>>> code block. =A0This means that when library(ascii) is run, an = empty line
>>> is collected and appended to the output. =A0Removing the "= ;output" header
>>> argument should fix this issue.
>>>
>>> My I ask why you are using the ascii package for simple table = output?
>>> It seems to me that this would be much simpler using the pure = Org-mode
>>> solution I suggested in my previous email.
>>>
>>> >
>>> > #+begin_src R :session *R* :results output org replace >>> > =A0 ascii(head(esoph))
>>> > #+end_src
>>> >
>>> > #+results: foo
>>> > | =A0 | agegp | alcgp =A0 =A0 | =A0 =A0tobgp | ncases | n= controls |
>>> > |---+-------+-----------+----------+--------+-----------|=
>>> > | 1 | 25-34 | 0-39g/day | 0-9g/day | =A0 0.00 | =A0 =A0 4= 0.00 |
>>> > | 2 | 25-34 | 0-39g/day | =A0 =A010-19 | =A0 0.00 | =A0 = =A0 10.00 |
>>> > | 3 | 25-34 | 0-39g/day | =A0 =A020-29 | =A0 0.00 | =A0 = =A0 =A06.00 |
>>> > | 4 | 25-34 | 0-39g/day | =A0 =A0 =A030+ | =A0 0.00 | =A0= =A0 =A05.00 |
>>> > | 5 | 25-34 | 40-79 =A0 =A0 | 0-9g/day | =A0 0.00 | =A0 = =A0 27.00 |
>>> > | 6 | 25-34 | 40-79 =A0 =A0 | =A0 =A010-19 | =A0 0.00 | = =A0 =A0 =A07.00 |
>>> >
>>> > Everything is then OK.
>>> > I have no idea why "library(ascii)..." generate= s an extra empty line in
>>> the
>>> > results.
>>> >
>>> > If I understand, the results is all the text directly und= er "#+results:",
>>> > until the first empty line. But what happens if the resul= t contains empty
>>> > lines? Here an example with ascii and Hmisc package:
>>> >
>>>
>>> This is not quite right, see [2] for a discussion of results h= andling.
>>> The "org" option to results is a special case in whi= ch no
>>> post-processing of the results takes place, and the raw output= is
>>> inserted into the org-mode buffer.
>>>
>>> Under normal usage w/o this header argument, results are eithe= r tabular
>>> or are textual. =A0If tabular a single table can easily be rec= ognized and
>>> handled, if textual they are normally enclosed in a block (exa= mple,
>>> html, latex, etc...), the block then allows for empty lines wh= ile still
>>> making it clear where the results end.
>>>
>>
>>
>>>
>>> >
>>> >> library(ascii)
>>> >> library(Hmisc)
>>> >> ascii(describe(esoph[, 1:3]))
>>> > #+CAPTION: esoph[, 1:3]
>>> > - 3 Variable
>>> > - 88 Observations
>>> >
>>> > *agegp*
>>> > | n =A0| missing | unique |
>>> > | 88 | 0 =A0 =A0 =A0 | 6 =A0 =A0 =A0|
>>> >
>>> > | =A0 =A0 =A0 =A0 =A0 | 25-34 | 35-44 | 45-54 | 55-64 | 6= 5-74 | 75+ |
>>> > | Frequency | 15 =A0 =A0| 15 =A0 =A0| 16 =A0 =A0| 16 =A0 = =A0| 15 =A0 =A0| 11 =A0|
>>> > | % =A0 =A0 =A0 =A0 | 17 =A0 =A0| 17 =A0 =A0| 18 =A0 =A0|= 18 =A0 =A0| 17 =A0 =A0| 12 =A0|
>>> >
>>> > *alcgp*
>>> > | n =A0| missing | unique |
>>> > | 88 | 0 =A0 =A0 =A0 | 4 =A0 =A0 =A0|
>>> >
>>> > =A00-39g/day (23, 26%), 40-79 (23, 26%), 80-119 (21, 24%)= , 120+ (21, 24%)
>>> >
>>> > *tobgp*
>>> > | n =A0| missing | unique |
>>> > | 88 | 0 =A0 =A0 =A0 | 4 =A0 =A0 =A0|
>>> >
>>> > =A00-9g/day (24, 27%), 10-19 (24, 27%), 20-29 (20, 23%), = 30+ (20, 23%)
>>> >
>>> > As you can see, describe() generate a description of my d= ata, and ascii
>>> > generate org-mode markup as result. The result contains e= mpty 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 w= orkaround?
>>> >
>>>
>>> When using ":results org" there is no workaround, as= the explicit
>>> purpose of this setting is for your results to be inserted dir= ectly into
>>> the Org-mode buffer w/o any interpretation or alteration.
>>>
>>
>>
>>>
>>> In general I would recommend keeping a 1-to-1 mapping between = code
>>> blocks and result items, which should resolve this issue.
>>>
>>> >
>>> > Of course, ascii is not usefull in this case, but it can = coerce into
>>> > org-mode markup many other R objects (see my previous exa= mple and
>>> > http://orgmode.org/worg/org-contrib/babel= /examples/ascii.php)
>>> >
>>>
>>> I see, that answers my question from above. Thanks
>>>
>>> Hope this helps -- Eric
>>>
>>> >
>>> > 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 packag= e. =A0It 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 o= f this the table
>>> >> isn't seen as results and is not replaced -- if y= ou 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 in= to Org-mode
>>> >> documents without using the ascii package. =A0For exa= mple the following
>>> >> would be a more idiomatic example of using Org-mode t= o create a table
>>> >> from R code.
>>> >>
>>> >> --8<---------------cut here---------------start---= ---------->8---
>>> >> #+begin_src R
>>> >> =A0numbers <- matrix(c(51,43,22,92,28,21,68,22,9),= ncol=3D3,byrow=3DTRUE)
>>> >> =A0numbers
>>> >> #+end_src
>>> >>
>>> >> #+results:
>>> >> | 51 | 43 | 22 |
>>> >> | 92 | 28 | 21 |
>>> >> | 68 | 22 | =A09 |
>>> >>
>>> >> #+begin_src R :colnames yes
>>> >> =A0numbers <- matrix(c(51,43,22,92,28,21,68,22,9),= ncol=3D3,byrow=3DTRUE)
>>> >> =A0numbers
>>> >> #+end_src
>>> >>
>>> >> #+results:
>>> >> | V1 | V2 | V3 |
>>> >> |----+----+----|
>>> >> | 51 | 43 | 22 |
>>> >> | 92 | 28 | 21 |
>>> >> | 68 | 22 | =A09 |
>>> >> --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*
>>> >> =A0 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 versi= on of org-mode:
>>> >> >
>>> >> > #+srcname: foo
>>> >> > #+begin_src R :session *R* :results output org r= eplace
>>> >> > =A0 library(ascii)
>>> >> > =A0 options(asciiType =3D "org")
>>> >> > =A0 ascii(head(esoph))
>>> >> > #+end_src
>>> >> >
>>> >> > #+results: foo
>>> >> >
>>> >> > =A0| =A0 | agegp | alcgp =A0 =A0 | tobgp =A0 =A0= | ncases | ncontrols |
>>> >> > |---+-------+-----------+----------+--------+---= --------|
>>> >> > | 1 | 25-34 | 0-39g/day | 0-9g/day | 0.00 =A0 | = 40.00 =A0 =A0 |
>>> >> > | 2 | 25-34 | 0-39g/day | 10-19 =A0 =A0| 0.00 = =A0 | 10.00 =A0 =A0 |
>>> >> > | 3 | 25-34 | 0-39g/day | 20-29 =A0 =A0| 0.00 = =A0 | 6.00 =A0 =A0 =A0|
>>> >> > | 4 | 25-34 | 0-39g/day | 30+ =A0 =A0 =A0| 0.00 = =A0 | 5.00 =A0 =A0 =A0|
>>> >> > | 5 | 25-34 | 40-79 =A0 =A0 | 0-9g/day | 0.00 = =A0 | 27.00 =A0 =A0 |
>>> >> > | 6 | 25-34 | 40-79 =A0 =A0 | 10-19 =A0 =A0| 0.0= 0 =A0 | 7.00 =A0 =A0 =A0|
>>> >> >
>>> >> > =A0| =A0 | agegp | alcgp =A0 =A0 | tobgp =A0 =A0= | ncases | ncontrols |
>>> >> > |---+-------+-----------+----------+--------+---= --------|
>>> >> > | 1 | 25-34 | 0-39g/day | 0-9g/day | 0.00 =A0 | = 40.00 =A0 =A0 |
>>> >> > | 2 | 25-34 | 0-39g/day | 10-19 =A0 =A0| 0.00 = =A0 | 10.00 =A0 =A0 |
>>> >> > | 3 | 25-34 | 0-39g/day | 20-29 =A0 =A0| 0.00 = =A0 | 6.00 =A0 =A0 =A0|
>>> >> > | 4 | 25-34 | 0-39g/day | 30+ =A0 =A0 =A0| 0.00 = =A0 | 5.00 =A0 =A0 =A0|
>>> >> > | 5 | 25-34 | 40-79 =A0 =A0 | 0-9g/day | 0.00 = =A0 | 27.00 =A0 =A0 |
>>> >> > | 6 | 25-34 | 40-79 =A0 =A0 | 10-19 =A0 =A0| 0.0= 0 =A0 | 7.00 =A0 =A0 =A0|
>>> >> >
>>> >> > There is no more ">", but an extra = space.
>>> >> > But, the replace option doesn't work: result= s are still appended. I am
>>> >> not
>>> >> > an org-mode guru (far, far away), but I think th= is is because when
>>> output
>>> >> is
>>> >> > org, there is no indication about the "end&= quot; 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 co= de:
>>> >> >>
>>> >> >> #+srcname: foo
>>> >> >> #+begin_src R :session *R* :results output o= rg replace
>>> >> >> =A0 library(ascii)
>>> >> >> =A0 options(asciiType =3D "org") >>> >> >> =A0 ascii(head(esoph))
>>> >> >> #+end_src
>>> >> >>
>>> >> >> #+results: foo
>>> >> >>
>>> >> >> > | =A0 | agegp | alcgp =A0 =A0 | tobgp = =A0 =A0| ncases | ncontrols |
>>> >> >> |---+-------+-----------+----------+--------= +-----------|
>>> >> >> | 1 | 25-34 | 0-39g/day | 0-9g/day | 0.00 = =A0 | 40.00 =A0 =A0 |
>>> >> >> | 2 | 25-34 | 0-39g/day | 10-19 =A0 =A0| 0.0= 0 =A0 | 10.00 =A0 =A0 |
>>> >> >> | 3 | 25-34 | 0-39g/day | 20-29 =A0 =A0| 0.0= 0 =A0 | 6.00 =A0 =A0 =A0|
>>> >> >> | 4 | 25-34 | 0-39g/day | 30+ =A0 =A0 =A0| 0= .00 =A0 | 5.00 =A0 =A0 =A0|
>>> >> >> | 5 | 25-34 | 40-79 =A0 =A0 | 0-9g/day | 0.0= 0 =A0 | 27.00 =A0 =A0 |
>>> >> >> | 6 | 25-34 | 40-79 =A0 =A0 | 10-19 =A0 =A0|= 0.00 =A0 | 7.00 =A0 =A0 =A0|
>>> >> >>
>>> >> >> > | =A0 | agegp | alcgp =A0 =A0 | tobgp = =A0 =A0| ncases | ncontrols |
>>> >> >> |---+-------+-----------+----------+--------= +-----------|
>>> >> >> | 1 | 25-34 | 0-39g/day | 0-9g/day | 0.00 = =A0 | 40.00 =A0 =A0 |
>>> >> >> | 2 | 25-34 | 0-39g/day | 10-19 =A0 =A0| 0.0= 0 =A0 | 10.00 =A0 =A0 |
>>> >> >> | 3 | 25-34 | 0-39g/day | 20-29 =A0 =A0| 0.0= 0 =A0 | 6.00 =A0 =A0 =A0|
>>> >> >> | 4 | 25-34 | 0-39g/day | 30+ =A0 =A0 =A0| 0= .00 =A0 | 5.00 =A0 =A0 =A0|
>>> >> >> | 5 | 25-34 | 40-79 =A0 =A0 | 0-9g/day | 0.0= 0 =A0 | 27.00 =A0 =A0 |
>>> >> >> | 6 | 25-34 | 40-79 =A0 =A0 | 10-19 =A0 =A0|= 0.00 =A0 | 7.00 =A0 =A0 =A0|
>>> >> >>
>>> >> >> With org-mode 7.01g in emacs 23, there is tw= o problems:
>>> >> >> =A0- an extra ">" is added in t= he first line while output is "org"
>>> >> >> =A0- when I run the code twice, the new resu= lts is appended, while I
>>> have
>>> >> the
>>> >> >> option "replace".
>>> >> >>
>>> >> >> Is there any problem with my header?
>>> >> >>
>>> >> >> Thank you very much for your help.
>>> >> >> David
>>> >> >>
>>> >> > _______________________________________________<= br> >>> >> > Emacs-orgmode mailing list
>>> >> > Please use `Reply All' to send replies to th= e list.
>>> >> >
Emacs-orgmode@gnu.org
>>> >> > http://lists.gnu.org/mailman/listinfo/ema= cs-orgmode
>>> >>
>>>
>>> Footnotes:
>>> [1] =A0http://orgmode.org/manual/Header-ar= guments.html#Header-arguments
>>>
>>> [2]
>>> http://orgmode.org/manual/Result= s-of-evaluation.html#Results-of-evaluation
>>>
>>>
>>> L'int=E9grit=E9 de ce message n'=E9tant pas assur=E9e = sur Internet, l'Institut
>>> Curie ne peut =EAtre tenu responsable de son contenu.
>>> Si vous n'=EAtes pas destinataire de ce message confidenti= el, 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.
>>>

Footnotes:
[1]
,----[org-babel-insert-result]
| org-babel-insert-result is a Lisp function in `ob.el'.
|
| (org-babel-insert-result RESULT &optional RESULT-PARAMS INFO HASH
| INDENT LANG)
|
| Insert RESULT into the current buffer.
| By default RESULT is inserted after the end of the
| current source block. =A0With optional argument RESULT-PARAMS
| controls insertion of results in the org-mode file.
| RESULT-PARAMS can take the following values...
|
| replace - (default option) insert results after the source block
| =A0 =A0 =A0 =A0 =A0 replacing any previously inserted results
|
| silent -- no results are inserted
|
| file ---- the results are interpreted as a file path, and are
| =A0 =A0 =A0 =A0 =A0 inserted into the buffer using the Org-mode file synt= ax
|
| raw ----- results are added directly to the org-mode file. =A0This
| =A0 =A0 =A0 =A0 =A0 is a good option if you code block will output org-mo= de
| =A0 =A0 =A0 =A0 =A0 formatted text.
|
| org ----- this is the same as the 'raw' option
|
| html ---- results are added inside of a #+BEGIN_HTML block. =A0This
| =A0 =A0 =A0 =A0 =A0 is a good option if you code block will output html | =A0 =A0 =A0 =A0 =A0 formatted text.
|
| latex --- results are added inside of a #+BEGIN_LATEX block.
| =A0 =A0 =A0 =A0 =A0 This is a good option if you code block will output | =A0 =A0 =A0 =A0 =A0 latex formatted text.
|
| code ---- the results are extracted in the syntax of the source
| =A0 =A0 =A0 =A0 =A0 code of the language being evaluated and are added | =A0 =A0 =A0 =A0 =A0 inside of a #+BEGIN_SRC block with the source-code | =A0 =A0 =A0 =A0 =A0 language set appropriately. =A0Note this relies on th= e
| =A0 =A0 =A0 =A0 =A0 optional LANG argument.
|
| [back]
`----

[2]
,----
| ob-org has two non-standard header arguments in that it exports it's<= br> | results by default and the result type defaults to raw, this ensures
| that the body of a begin_src org block exports transparently.
|
| This is a breaking change in that if you are currently using org
| code blocks to export org-fontified code you will have to set the
| ":exports" header argument for org-mode blocks to "code&qu= ot; on a block,
| file, language or system-wide basis.
`----


--001485f7c3564d52fa048ec102a9-- --===============2092494195== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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 --===============2092494195==--