emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Global variables in Org mode document with source blocks


From: Lennart C. Karssen
Subject: Global variables in Org mode document with source blocks
Date: Tue, 18 May 2021 15:57:28 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1

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
do_some_check_here_on_someData

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

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
else
 echo "One or more checks *failed!*"
fi
#+end_src


Best regards,

Lennart.

-- 
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
L.C. Karssen
The Netherlands

lennart@karssen.org
http://blog.karssen.org
GPG key ID: A88F554A
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]