emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Lennart C. Karssen" <lennart@karssen.org>
To: emacs-orgmode@gnu.org
Subject: Global variables in Org mode document with source blocks
Date: Tue, 18 May 2021 15:57:28 +0200	[thread overview]
Message-ID: <56b14034-f6c4-0528-9235-e0fb9f3f1f28@karssen.org> (raw)

[-- Attachment #1.1: Type: text/plain, Size: 1609 bytes --]

Dear list,

I am working on a dynamic report in Org mode, where I use source blocks
in various languages to process data. Several blocks produce text or
tables that become part of the PDF on export.

The final chapter should state whether all checks passed, or whether one
or more failed (it is not necessary to know which step failed).

In a single language environment, I would use a variable (called e.g.
nrChecksFailed) that would be incremented for each failing check. In a
single language Org document this could probably be done with a
:session, but given that I mix Awk, Bash, Emacs lisp and R that doesn't
look like the way to go. Do Org documents/source blocks have some
concept of a (global) variable that I can pass to my SRC blocks and
increment inside them?

E.g. after somehow initialising nrChecksFailed = 0, I would like to do:

#+header :var nFailed=nrChecksFailed :var someData=someData
#+begin_src R :results raw

if (check_results_OK) {
  cat("check A passed\n")
} else {
  cat("check A *failed*\n")
  nFailed <- nFailed + 1

So that in my conclusion chapter I can do for example:

#+header: :var nFailed=nrChecksFailed
#+begin_src bash  :results raw
if [[ nFailed -eq 0 ]]; then
  echo "All checks passed
 echo "One or more checks *failed!*"

Best regards,


L.C. Karssen
The Netherlands

GPG key ID: A88F554A

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

             reply	other threads:[~2021-05-18 13:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-18 13:57 Lennart C. Karssen [this message]
2021-05-18 15:03 ` Global variables in Org mode document with source blocks John Kitchin
2021-05-25 14:22   ` Lennart C. Karssen
2021-05-18 17:25 ` Greg Minshall
2021-05-25 14:27   ` Lennart C. Karssen

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:

  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=56b14034-f6c4-0528-9235-e0fb9f3f1f28@karssen.org \
    --to=lennart@karssen.org \
    --cc=emacs-orgmode@gnu.org \


* 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


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