DONE Add append to results handling

  • State "DONE" from "PROPOSED" 2010-06-07 Mon 16:46
  • State "PROPOSED" from "TODO" 2010-06-05 Sat 19:11
  • State "TODO" from "PROPOSED" 2010-06-05 Sat 19:02
  • State "PROPOSED" from "" 2010-04-01 Thu 10:34

(implemented while fixing the results deletion and insertion bug)

I'm developing general purpose org-babel functions that run queries for frequently performed analyses. In some instances it isn't possible to make the queries completely general, so I'm left with combining the results of two or more separate calls to the org-babel functions.

This is an example. Two runs are needed to make a table with coral abraders and basalt manuports, when there are also basalt abraders and coral manuports in the data table. If I set material="('coral', 'basalt')" and class="('abrader','manuport') then I get all four types of artifact in the results.

q <- sprintf("SELECT c.context, a.class,
round(sum(a.weight),1) AS weight FROM artifacts a, baglist b,
context c WHERE a.bag = b.bag AND b.context = c.context AND
a.project = %i and b.project = %i and c.project = %i AND a.class IN %s
AND a.material IN %s AND c.context_type = 'cultural' AND c.duration IN %s  AND b.context >= %i AND b.context <= %i group by 1,
2 order by 1, 2", project, project, project, class, material, duration, start,
end)

art.wt <- dbGetQuery(con, q)

art.wt

It would be useful in this case, and perhaps other cases, to have a :results append argument. An org-mode table would be created if it is absent, or the function results would be appended to an existing results table if present.

EMS thoughts

this seems like a good idea, and should be easy to implement. The next step would be to allow pre-pending or insertion at arbitrary points in the table, or to define combining functions (e.g. if the result is a scalar rather than a table to sum, or multiply, or concatenate the values), this then comes full-circle back to maybe the results block should just be another argument to the code block (which raises an issue of circular code block calls, and a related issue of controlling whether a block need be re-run if it's results already exist in the buffer), and appending shouldn't be explicitly built into org-babel.

Hmm, I see three good options here – there are certainly more;

  1. sort out all issues related to re-running code blocks which already have in-buffer results s.t. it is possible for a block to reference it's own results
  2. add a simple append option
  3. add something like results incorporating functions which could provide a more generic functionality subsuming appending of functions