emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: Kierin Bell <bellkierin@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: Inserting arbitrary lines before tables with Babel
Date: Sun, 30 Oct 2022 04:43:22 +0000	[thread overview]
Message-ID: <87r0ypaplh.fsf@localhost> (raw)
In-Reply-To: <87wn8ibam4.fsf@gmail.com>

Kierin Bell <bellkierin@gmail.com> writes:

> When evaluating Babel code blocks with a ':results table' header
> argument, what is the best way to automatically insert text _outside_
> of the table?
>
> For example, if I have a source block:
> #+NAME: get-random-table
> #+begin_src R :var length=12 :results table
>   runif(length)
> #+end_src
>
> ... Then 'org-babel-execute-maybe' (C-c C-v e) will output a nicely
> formatted Org table:
> #+RESULTS: get-random-table
> |  0.645291731692851 |
> | 0.0425670417025685 |
> |  0.220107783330604 |
> |  0.413881630403921 |
> |  0.817712268792093 |
> |  0.972381719155237 |
>
> ... But if I want to insert a line, for example containing a 'NAME'
> keyword, before and _outside of_ that table, there seems to be no easy
> way to do this automatically.

Just insert it right before #+results keyword. #+results is just another
affiliated keyword and can be combined with others.

#+NAME: random-table-1
#+RESULTS: get-random-table
|  0.645291731692851 |
| 0.0425670417025685 |
|  0.220107783330604 |
|  0.413881630403921 |
|  0.817712268792093 |
|  0.972381719155237 |

Also, if you use :exports results, you can refer to the table as
"get-random-table" - the same with the source block name.

> Trying to insert lines using subsequent code blocks (arguments, noweb,
> etc.) will either strip Org table formatting or add additional lines
> within the table instead of outside of it (depending on the ':results'
> arguments). There is the same problem with using a ':post' header
> argument, and ':wrap' does not allow arbitrary insertion of individual
> lines.

What is wrong with the example in 16.6 Results of Evaluation? It shows
how to prepend #+ATTR_LATEX :width 5cm. #+NAME: would be the same.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


      reply	other threads:[~2022-10-30  4:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-29 21:09 Inserting arbitrary lines before tables with Babel Kierin Bell
2022-10-30  4:43 ` Ihor Radchenko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r0ypaplh.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=bellkierin@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).