- [[* reference to data and evaluation results][reference to data and evaluation results]]
- [[* reference format][reference format]]
- [[* source-target pairs][source-target pairs]]
- [[* source block output from org tables][source block output from org tables]]
- [[* source block outpt from other source block][source block outpt from other source block]]
- [[* source block output from org list][source block output from org list]] ?? maybe
- [[* org table from source block][org table from source block]]
- [[* org table from org table][org table from org table]]
- [[* org properties from source block][org properties from source block]]
- [[* org properties from org table][org properties from org table]]
- [[* export][export]]
* Objectives and Specs
** evaluation of embedded source code
*** execution on demand and on export
Let's use an asterisk to indicate content which includes the
*result* of code evaluation, rather than the code itself. Clearly
we have a requirement for the following transformation:
org \to org*
Let's say this transformation is effected by a function
`org-eval-buffer'. This transformation is necessary when the
target format is org (say you want to update the values in an org
table, or generate a plot and create an org link to it), and it
can also be used as the first step by which to reach html and
latex:
org \to org* \to html
org \to org* \to latex
Thus in principle we can reach our 3 target formats with
`org-eval-buffer', `org-export-as-latex' and `org-export-as-html'.
An extra transformation that we might want is
org \to latex
I.e. export to latex without evaluation of code, in such a way that R
code can subsequently be evaluated using
=Sweave(driver=RweaveLatex)=, which is what the R community is
used to. This would provide a `bail out' avenue where users can
escape org mode and enter a workflow in which the latex/noweb file
is treated as source.
**** How do we implement `org-eval-buffer'?
AIUI The following can all be viewed as implementations of
org-eval-buffer for R code:
(see this question again posed in [[file:org-babel/org-babel-R.el::Maybe%20the%20following%20be%20replaced%20with%20a%20method%20using%20ess%20execute][org-babel-R.el]])
***** org-eval-light
This is the beginnings of a general evaluation mechanism, that
could evaluate python, ruby, shell, perl, in addition to R.
The header says it's based on org-eval
what is org-eval??
org-eval was written by Carsten. It lives in the
org/contrib/lisp directory because it is too dangerous to
include in the base. Unlike org-eval-light org-eval evaluates
all source blocks in an org-file when the file is first opened,
which could be a security nightmare for example if someone
emailed you a pernicious file.
***** org-R
This accomplishes org \to org* in elisp by visiting code blocks
then press =\C-c\C-c= inside of the following src code snippet. The
results should appear in a comment immediately following the source
code block. It shouldn't be too hard to add R support to this
function through the `org-eval-light-interpreters' variable.
(Dan: The following causes error on export to HTML hence spaces inserted at bol)
#+begin_src shell
date
#+end_src
*** existing formats
**** Source code blocks
Org has an extremely useful method of editing source code and
examples in their native modes. In the case of R code, we want to
be able to use the full functionality of ESS mode, including
interactive evaluation of code.
Source code blocks look like the following and allow for the
special editing of code inside of the block through
`org-edit-special'.
#+BEGIN_SRC r
,## hit C-c ' within this block to enter a temporary buffer in r-mode.
,## while in the temporary buffer, hit C-c C-c on this comment to
,## evaluate this block
a <- 3
a
,## hit C-c ' to exit the temporary buffer
#+END_SRC
**** dblocks
dblocks are useful because org-mode will automatically call
`org-dblock-write:dblock-type' where dblock-type is the string
following the =#+BEGIN:= portion of the line.
dblocks look like the following and allow for evaluation of the
code inside of the block by calling =\C-c\C-c= on the header of
the block.
#+BEGIN: dblock-type
#+END:
**** R blocks
In developing RweaveOrg, Austin created [[file:existing_tools/RweaveOrg/org-sweave.el][org-sweave.el]]. This
allows for the kind of blocks shown in [[file:existing_tools/RweaveOrg/testing.Rorg][testing.Rorg]]. These blocks
have the advantage of accepting options to the Sweave preprocessor
following the #+BEGIN_R declaration.
*** block headers/parameters
Regardless of the syntax/format chosen for the source blocks, we will
need to be able to pass a list of parameters to these blocks. These
should include (but should certainly not be limited to)
- label or id :: Label of the block, should we provide facilities for
automatically generating a unique one of these?
- file :: names of file to which graphical/textual/numerical/tabular output
should be written. Do we need this, or should this be controlled
through the source code itself?
- results :: indication of where the results should be placed, maybe
the following values...
- append ::*default* meaning just append to the current buffer
immediately following the current source block
- replace :: like append, but replace any results currently there
- file :: save the results in a new file, and place a link to the
file into the current buffer immediately following the
source code block
- table :: save the results into a table, maybe use a table id:range
to identify which table and where therein
- nil :: meaning just discard the results
- not sure of a good name here :: flags for when/if the block should
be evaluated (on export etc...)
- again can't thing of a concise name :: flags for how the results of
the export should be displayed/included
- scope :: flag indicating whether the block should have a local or
global scope
- flags specific to the language of the source block
- etc...
I think fleshing out this list is an important next step.
** Interaction with the R process
We should take care to implement this in such a way that all of the
different components which have to interactive with R including:
- evaluation of source code blocks
- automatic evaluation on export
- evaluation of \R{} snippets
- evaluation of single source code lines
- evaluation of included source code files
- sending/receiving vector data
I think we currently have two implementations of interaction with R
processes; [[file:existing_tools/org-R.el][org-R.el]] and [[file:existing_tools/exp-blocks/org-exp-blocks.el ][org-exp-blocks.el]]. We should be sure to take
the best of each of these approaches.
More on the exchange of data at between org-mode and source code
blocks at [[* reference to data and evaluation results][reference to data and evaluation results]].
** block scoping
(see [[* caching of evaluation][caching of evaluation]])
This inadvertently raises the issue of scoping. The pretend function
pretends that we will create a block-local scope, and that we can save
just the things in that scope. Sweave takes the make-everything-global
approach. I can see advantages either way. If we make block-local
scopes, we can save each one independently, and generally speaking it
seems like more granularity==more control. If we make everything
global, we can refer to entities declared in earlier blocks without
having to explicitly import those entities into the current block. I
think this counts in the "need to think about it early on" category.
If we did want block-local scopes, in R we can start every eval with
something like
;; fake code that pretends to create a new, empty environment