# Naming the result of a source block

The following question has been asked (in slightly different form) in a comment of another answer:

Is it possible to name the results of a source block with #+NAME: foobar (or equivalently but old-style: #+TBLNAME: foobar) rather than #+RESULTS: foobar?

Example:

#+NAME: foo
#+BEGIN_SRC emacs-lisp :var alpha=2 :results value
(let* ((tol 0.1)
(alpha_1 (- 90 alpha)))
(("angle" "symbol"   "value"  "max"         "min") hline
("toe"   "\\alpha"   ,alpha  ,(+ alpha tol)  ,(- alpha tol))
("c"   "\\alpha_1"   ,alpha_1  ,(+ alpha_1 tol)  ,(- alpha_1 tol))
))
#+END_SRC

#+RESULTS: foo
| angle | symbol   | value |  max |  min |
|-------+----------+-------+------+------|
| toe   | \alpha   |     1 |  1.1 |  0.9 |
| c     | \alpha_1 |    89 | 89.1 | 88.9 |


One can add the following lines below unnamed source blocks (with bar replaced by the intended table name):

#+NAME: bar
#+RESULTS:
||


The line with #+name: bar is preserved after the evaluation of the source block and || is replaced with the resulting table.

Note, that the name bar really names the table and not the source block. That has the following consequences (probably among others I am not aware of at the moment):

1. If you refer to the table name in the header arguments of another source block, say buh, then the bar source block is not reevaluated when buh is evaluated. The table is not updated but taken as argument for buh as it is.
One can call org-babel-execute-buffer to get correctly updated results.

2. If the source block returns a string containing the formatted org-table rather than table data referring to the source block name in header variables gets you the string and not the table data. That is most often unwanted.
In that case it is a big advantage that you can alternatively refer to the resulting table by its name.

If the source block is named, e.g., foo replace #+RESULTS: with #+RESULTS: foo.

Example:

#+NAME: foo
#+BEGIN_SRC emacs-lisp :var alpha=2 :results value
(let* ((tol 0.1)
(alpha_1 (- 90 alpha)))
(("angle" "symbol"   "value"  "max"         "min") hline
("toe"   "\\alpha"   ,alpha  ,(+ alpha tol)  ,(- alpha tol))
("c"   "\\alpha_1"   ,alpha_1  ,(+ alpha_1 tol)  ,(- alpha_1 tol))
))
#+END_SRC

#+TBLNAME: bar
#+RESULTS: foo
| angle | symbol   | value |  max |  min |
|-------+----------+-------+------+------|
| toe   | \alpha   |     1 |  1.1 |  0.9 |
| c     | \alpha_1 |    89 | 89.1 | 88.9 |

#+CALL: foo(alpha=bar[2,3])

#+NAME: buh
#+RESULTS:
| angle | symbol   | value |                max |               min |
|-------+----------+-------+--------------------+-------------------|
| toe   | \alpha   |   1.1 | 1.2000000000000002 |               1.0 |
| c     | \alpha_1 |  88.9 |               89.0 | 88.80000000000001 |


The example demonstrates the update problem. The header variable alpha had the value 1 at the first evaluation of foo. Afterwards the value was changed to 2 but the source block foo was not evaluated again.
The evaluation of the #+CALL statement does use the table value 1.1 at cell 2,3 directly without reevaluation of foo.

• Quite informative, indeed. But there seems to be no way to not have the line #+RESULTS: in the results. One interesting question is, how is the system handling a let* form and turning it into a table? Is this something to do with :results value? But then if I do #+begin_src emacs-lisp :var table=bar (message "%S" table) #+end_src I get (("toe" "\\alpha" 2 2.1 1.9) ("c" "$\\alpha_1$" 88 88.1 87.9)) i.e., it's left out the title and horizontal line, i.e.,i.e., not completely reversible? Interesting stuff, nonetheless. Apr 17 '19 at 4:07