emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Global variables in Org mode document with source blocks
@ 2021-05-18 13:57 Lennart C. Karssen
  2021-05-18 15:03 ` John Kitchin
  2021-05-18 17:25 ` Greg Minshall
  0 siblings, 2 replies; 5+ messages in thread
From: Lennart C. Karssen @ 2021-05-18 13:57 UTC (permalink / raw)
  To: emacs-orgmode

[-- 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 --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-05-25 14:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-18 13:57 Global variables in Org mode document with source blocks Lennart C. Karssen
2021-05-18 15:03 ` 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

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