emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Out of Order Evaluation
@ 2014-03-20 22:02 Michael Weylandt
  2014-03-20 22:13 ` Andreas Leha
  2014-03-24  2:06 ` Eric Schulte
  0 siblings, 2 replies; 7+ messages in thread
From: Michael Weylandt @ 2014-03-20 22:02 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

Hi, 

I want to put a summary of my analysis at the beginning of a document using results calculated at the end of the document. Is this possible? 

#=========
#+TITLE: Test
#+AUTHOR: Michael Weylandt
#+PROPERTY: header-args:R :session *__R__* :exports both

* Summary
The mean result was src_R[:exports results]{mean(x)}

* Analysis, 
We do some complicated calculations: 

#+BEGIN_SRC R
x <- rnorm(5)
#+END_SRC
#=========

Is this possible in a single pass? I've played with #+NAME and <<block()>> but haven't gotten the out-of-order evaluation quite right. 

Michael

(Bonus question, is there a way to not have to put ":exports results" in inline blocks?)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Out of Order Evaluation
  2014-03-20 22:02 Out of Order Evaluation Michael Weylandt
@ 2014-03-20 22:13 ` Andreas Leha
  2014-03-21  1:34   ` Charles Berry
  2014-03-24  2:06 ` Eric Schulte
  1 sibling, 1 reply; 7+ messages in thread
From: Andreas Leha @ 2014-03-20 22:13 UTC (permalink / raw)
  To: emacs-orgmode

Hi Michael,

Michael Weylandt <michael.weylandt@gmail.com> writes:

> Hi, 
>
> I want to put a summary of my analysis at the beginning of a document
> using results calculated at the end of the document. Is this possible?
>
> #=========
> #+TITLE: Test
> #+AUTHOR: Michael Weylandt
> #+PROPERTY: header-args:R :session *__R__* :exports both
>
> * Summary
> The mean result was src_R[:exports results]{mean(x)}
>
> * Analysis, 
> We do some complicated calculations: 
>
> #+BEGIN_SRC R
> x <- rnorm(5)
> #+END_SRC
> #=========
>
> Is this possible in a single pass? I've played with #+NAME and
> <<block()>> but haven't gotten the out-of-order evaluation quite
> right.
>
> Michael
>

How about something along:

--8<---------------cut here---------------start------------->8---
#+TITLE: Test
#+AUTHOR: Michael Weylandt
#+PROPERTY: header-args:R :session *__R__* :exports both

* Summary
The mean result was src_R[:exports results :var analysisresults=theanalysis()]{mean(unlist(analysisresults))}

* Analysis, 
We do some complicated calculations: 

#+name: theanalysis
#+BEGIN_SRC R
x <- rnorm(5)
#+END_SRC
--8<---------------cut here---------------end--------------->8---

Regards,
Andreas

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Out of Order Evaluation
  2014-03-20 22:13 ` Andreas Leha
@ 2014-03-21  1:34   ` Charles Berry
  2014-03-21  8:01     ` Andreas Leha
  2014-03-21 18:51     ` Michael Weylandt
  0 siblings, 2 replies; 7+ messages in thread
From: Charles Berry @ 2014-03-21  1:34 UTC (permalink / raw)
  To: emacs-orgmode

Andreas Leha <andreas.leha <at> med.uni-goettingen.de> writes:

> 
> Hi Michael,
> 
> Michael Weylandt <michael.weylandt <at> gmail.com> writes:
> 
> > Hi, 
> >
> > I want to put a summary of my analysis at the beginning of a document
> > using results calculated at the end of the document. Is this possible?

[snip]

> >
> > Is this possible in a single pass? 


Not quite. The method suggested by Andreas computes the result twice. If
there is any randomness in the results (as in the example) you will get a 
different answer in the summary than when the block is later evaluated.

> > I've played with #+NAME and
> > <<block()>> but haven't gotten the out-of-order evaluation quite
> > right.

You can use

#+results: the-mean

before 

#+NAME: the-mean
#+begin_src R
mean(x)
#+end_src

which is after 'theanalysis' block.

And if the format is not pleasing add a filter that reformats the result.


> >
> > Michael
> >
> 
> How about something along:
> 
> --8<---------------cut here---------------start------------->8---
> #+TITLE: Test
> #+AUTHOR: Michael Weylandt
> #+PROPERTY: header-args:R :session *__R__* :exports both
> 
> * Summary
> The mean result was src_R[:exports results :var
analysisresults=theanalysis()]{mean(unlist(analysisresults))}
> 
> * Analysis, 
> We do some complicated calculations: 
> 
> #+name: theanalysis
> #+BEGIN_SRC R
> x <- rnorm(5)
> #+END_SRC
> --8<---------------cut here---------------end--------------->8---


It might be better to mark all the blocks in the doc ':eval never'
and ':exports code' or ':exports none' and put blocks before the first 
headline that do all the calcs from noweb references, and put the #+results
lines (if you need them) wherever you want them in the doc. Like so:



--8<---------------cut here---------------start------------->8---
#+TITLE: Test
#+AUTHOR: Michael Weylandt
#+PROPERTY: header-args:R :session *__R__* :exports both


#+NAME: master
#+BEGIN_SRC R :noweb yes :results silent :exports results
<<theanalysis>>
#+END_SRC

* Summary


The mean result was  src_R[:exports results]{mean(x)}

* Analysis, 
We do some complicated calculations: 

#+name: theanalysis
#+BEGIN_SRC R :eval never :exports code
x <- rnorm(5)
#+END_SRC

--8<---------------cut here---------------end--------------->8---

IMO, needing ':exports results' for inline src blocks is a bug not a
feature. 

HTH,

Chuck

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Out of Order Evaluation
  2014-03-21  1:34   ` Charles Berry
@ 2014-03-21  8:01     ` Andreas Leha
  2014-03-21  8:15       ` Andreas Leha
  2014-03-21 18:51     ` Michael Weylandt
  1 sibling, 1 reply; 7+ messages in thread
From: Andreas Leha @ 2014-03-21  8:01 UTC (permalink / raw)
  To: emacs-orgmode

Charles Berry <ccberry@ucsd.edu> writes:

> Andreas Leha <andreas.leha <at> med.uni-goettingen.de> writes:
>
>> 
>> Hi Michael,
>> 
>> Michael Weylandt <michael.weylandt <at> gmail.com> writes:
>> 
>> > Hi, 
>> >
>> > I want to put a summary of my analysis at the beginning of a document
>> > using results calculated at the end of the document. Is this possible?
>
> [snip]
>
>> >
>> > Is this possible in a single pass? 
>
>
> Not quite. The method suggested by Andreas computes the result twice. If
> there is any randomness in the results (as in the example) you will get a 
> different answer in the summary than when the block is later evaluated.
>

Well, you could enter the ':cache yes' world here.  Although, for me,
that produced more problems than it solved (since there is no tracking
of dependencies among code blocks in :session mode).

My typical workflow now is something 'less literate':  My typical
project Org file will look like this:

--8<---------------cut here---------------start------------->8---
* Execution
This is full of #+call: lines.  By (my own) convention, this subtree has
to be evaluated before exporting the next subsection.

* Report
This is the report / presentation.

* Analysis
This contains all the code block to be called from the Execution
subtree.
(Plus usually quite a lot of code blocks from dead ends of the
project...)
--8<---------------cut here---------------end--------------->8---


This solves your problem (and is along the lines Charles suggests as
well), but requires more work than just export the document and is,
thus, less literate.

Regards,
Andreas



>> > I've played with #+NAME and
>> > <<block()>> but haven't gotten the out-of-order evaluation quite
>> > right.
>
> You can use
>
> #+results: the-mean
>
> before 
>
> #+NAME: the-mean
> #+begin_src R
> mean(x)
> #+end_src
>
> which is after 'theanalysis' block.
>
> And if the format is not pleasing add a filter that reformats the result.
>
>
>> >
>> > Michael
>> >
>> 
>> How about something along:
>> 
>> --8<---------------cut here---------------start------------->8---
>> #+TITLE: Test
>> #+AUTHOR: Michael Weylandt
>> #+PROPERTY: header-args:R :session *__R__* :exports both
>> 
>> * Summary
>> The mean result was src_R[:exports results :var
> analysisresults=theanalysis()]{mean(unlist(analysisresults))}
>> 
>> * Analysis, 
>> We do some complicated calculations: 
>> 
>> #+name: theanalysis
>> #+BEGIN_SRC R
>> x <- rnorm(5)
>> #+END_SRC
>> --8<---------------cut here---------------end--------------->8---
>
>
> It might be better to mark all the blocks in the doc ':eval never'
> and ':exports code' or ':exports none' and put blocks before the first 
> headline that do all the calcs from noweb references, and put the #+results
> lines (if you need them) wherever you want them in the doc. Like so:
>
>
>
> #+TITLE: Test
> #+AUTHOR: Michael Weylandt
> #+PROPERTY: header-args:R :session *__R__* :exports both
>
>
> #+NAME: master
> #+BEGIN_SRC R :noweb yes :results silent :exports results
> <<theanalysis>>
> #+END_SRC
>
> * Summary
>
>
> The mean result was  src_R[:exports results]{mean(x)}
>
> * Analysis, 
> We do some complicated calculations: 
>
> #+name: theanalysis
> #+BEGIN_SRC R :eval never :exports code
> x <- rnorm(5)
> #+END_SRC
>
>
> IMO, needing ':exports results' for inline src blocks is a bug not a
> feature. 
>
> HTH,
>
> Chuck

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Out of Order Evaluation
  2014-03-21  8:01     ` Andreas Leha
@ 2014-03-21  8:15       ` Andreas Leha
  0 siblings, 0 replies; 7+ messages in thread
From: Andreas Leha @ 2014-03-21  8:15 UTC (permalink / raw)
  To: emacs-orgmode

Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:

> Charles Berry <ccberry@ucsd.edu> writes:
>
>> Andreas Leha <andreas.leha <at> med.uni-goettingen.de> writes:
>>
>>> 
>>> Hi Michael,
>>> 
>>> Michael Weylandt <michael.weylandt <at> gmail.com> writes:
>>> 
>>> > Hi, 
>>> >
>>> > I want to put a summary of my analysis at the beginning of a document
>>> > using results calculated at the end of the document. Is this possible?
>>
>> [snip]
>>
>>> >
>>> > Is this possible in a single pass? 
>>
>>
>> Not quite. The method suggested by Andreas computes the result twice. If
>> there is any randomness in the results (as in the example) you will get a 
>> different answer in the summary than when the block is later evaluated.
>>
>
> Well, you could enter the ':cache yes' world here.  Although, for me,
> that produced more problems than it solved (since there is no tracking
> of dependencies among code blocks in :session mode).
>
> My typical workflow now is something 'less literate':  My typical
> project Org file will look like this:
>
> * Execution
> This is full of #+call: lines.  By (my own) convention, this subtree has
> to be evaluated before exporting the next subsection.
>
> * Report
> This is the report / presentation.
>
> * Analysis
> This contains all the code block to be called from the Execution
> subtree.
> (Plus usually quite a lot of code blocks from dead ends of the
> project...)
>
>
> This solves your problem (and is along the lines Charles suggests as
> well), but requires more work than just export the document and is,
> thus, less literate.

I should add here, that working with #+call lines is not too convenient.
These are missing some functionality compared to source blocks.  Most
importantly 'C-c C-v v' and 'C-c C-v n' are missing.  I wanted to have a
look at those for quite some time, but have not gotten around to do so.

Regards,
Andreas



>
> Regards,
> Andreas
>
>
>
>>> > I've played with #+NAME and
>>> > <<block()>> but haven't gotten the out-of-order evaluation quite
>>> > right.
>>
>> You can use
>>
>> #+results: the-mean
>>
>> before 
>>
>> #+NAME: the-mean
>> #+begin_src R
>> mean(x)
>> #+end_src
>>
>> which is after 'theanalysis' block.
>>
>> And if the format is not pleasing add a filter that reformats the result.
>>
>>
>>> >
>>> > Michael
>>> >
>>> 
>>> How about something along:
>>> 
>>> --8<---------------cut here---------------start------------->8---
>>> #+TITLE: Test
>>> #+AUTHOR: Michael Weylandt
>>> #+PROPERTY: header-args:R :session *__R__* :exports both
>>> 
>>> * Summary
>>> The mean result was src_R[:exports results :var
>> analysisresults=theanalysis()]{mean(unlist(analysisresults))}
>>> 
>>> * Analysis, 
>>> We do some complicated calculations: 
>>> 
>>> #+name: theanalysis
>>> #+BEGIN_SRC R
>>> x <- rnorm(5)
>>> #+END_SRC
>>> --8<---------------cut here---------------end--------------->8---
>>
>>
>> It might be better to mark all the blocks in the doc ':eval never'
>> and ':exports code' or ':exports none' and put blocks before the first 
>> headline that do all the calcs from noweb references, and put the #+results
>> lines (if you need them) wherever you want them in the doc. Like so:
>>
>>
>>
>> #+TITLE: Test
>> #+AUTHOR: Michael Weylandt
>> #+PROPERTY: header-args:R :session *__R__* :exports both
>>
>>
>> #+NAME: master
>> #+BEGIN_SRC R :noweb yes :results silent :exports results
>> <<theanalysis>>
>> #+END_SRC
>>
>> * Summary
>>
>>
>> The mean result was  src_R[:exports results]{mean(x)}
>>
>> * Analysis, 
>> We do some complicated calculations: 
>>
>> #+name: theanalysis
>> #+BEGIN_SRC R :eval never :exports code
>> x <- rnorm(5)
>> #+END_SRC
>>
>>
>> IMO, needing ':exports results' for inline src blocks is a bug not a
>> feature. 
>>
>> HTH,
>>
>> Chuck

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Out of Order Evaluation
  2014-03-21  1:34   ` Charles Berry
  2014-03-21  8:01     ` Andreas Leha
@ 2014-03-21 18:51     ` Michael Weylandt
  1 sibling, 0 replies; 7+ messages in thread
From: Michael Weylandt @ 2014-03-21 18:51 UTC (permalink / raw)
  To: Charles Berry; +Cc: emacs-orgmode@gnu.org



On Mar 20, 2014, at 21:34, Charles Berry <ccberry@ucsd.edu> wrote:

> Andreas Leha <andreas.leha <at> med.uni-goettingen.de> writes:
> 
>> 
>> Hi Michael,
>> 
>> Michael Weylandt <michael.weylandt <at> gmail.com> writes:
>> 
>>> Hi, 
>>> 
>>> I want to put a summary of my analysis at the beginning of a document
>>> using results calculated at the end of the document. Is this possible?
> 
> [snip]
> 
>>> 
>>> Is this possible in a single pass?
> 
> 
> Not quite. The method suggested by Andreas computes the result twice. If
> there is any randomness in the results (as in the example) you will get a 
> different answer in the summary than when the block is later evaluated.
> 
>>> I've played with #+NAME and
>>> <<block()>> but haven't gotten the out-of-order evaluation quite
>>> right.
> 
> You can use
> 
> #+results: the-mean
> 
> before 
> 
> #+NAME: the-mean
> #+begin_src R
> mean(x)
> #+end_src
> 
> which is after 'theanalysis' block.
> 
> And if the format is not pleasing add a filter that reformats the results

Great. The named result block is just what I needed. 

> 
> IMO, needing ':exports results' for inline src blocks is a bug not a
> feature. 
> 

Agreed, particularly in light of Eric's comments at 

http://lists.gnu.org/archive/html/emacs-orgmode/2014-03/msg00285.html

There's the variable org-babel-inline-header-args, but it seems using

#+PROPERTY: header-args :exports both

overrules/breaks it

Would org want something like 

#+PROPERTY: inline-header-args :exports results 

Or just 'hard-code' :exports results for all inline blocks?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Out of Order Evaluation
  2014-03-20 22:02 Out of Order Evaluation Michael Weylandt
  2014-03-20 22:13 ` Andreas Leha
@ 2014-03-24  2:06 ` Eric Schulte
  1 sibling, 0 replies; 7+ messages in thread
From: Eric Schulte @ 2014-03-24  2:06 UTC (permalink / raw)
  To: Michael Weylandt; +Cc: emacs-orgmode@gnu.org

Michael Weylandt <michael.weylandt@gmail.com> writes:

> Hi, 
>
> I want to put a summary of my analysis at the beginning of a document
> using results calculated at the end of the document. Is this possible?
>

Yes, simply place the calculation in a subtree marked with :noexport at
the top of the document.

Best,

>
> #=========
> #+TITLE: Test
> #+AUTHOR: Michael Weylandt
> #+PROPERTY: header-args:R :session *__R__* :exports both
>
> * Summary
> The mean result was src_R[:exports results]{mean(x)}
>
> * Analysis, 
> We do some complicated calculations: 
>
> #+BEGIN_SRC R
> x <- rnorm(5)
> #+END_SRC
> #=========
>
> Is this possible in a single pass? I've played with #+NAME and
> <<block()>> but haven't gotten the out-of-order evaluation quite
> right.
>
> Michael
>
> (Bonus question, is there a way to not have to put ":exports results" in inline blocks?)

-- 
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-03-24  2:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-20 22:02 Out of Order Evaluation Michael Weylandt
2014-03-20 22:13 ` Andreas Leha
2014-03-21  1:34   ` Charles Berry
2014-03-21  8:01     ` Andreas Leha
2014-03-21  8:15       ` Andreas Leha
2014-03-21 18:51     ` Michael Weylandt
2014-03-24  2:06 ` Eric Schulte

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).