From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <emacs-orgmode-bounces+larch=yhetil.org@gnu.org>
Received: from mp1 ([2001:41d0:2:bcc0::])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	by ms0.migadu.com with LMTPS
	id UBW9DxDIo2DkJgAAgWs5BA
	(envelope-from <emacs-orgmode-bounces+larch=yhetil.org@gnu.org>)
	for <larch@yhetil.org>; Tue, 18 May 2021 15:58:40 +0200
Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	by mp1 with LMTPS
	id MDdvCxDIo2AbOAAAbx9fmQ
	(envelope-from <emacs-orgmode-bounces+larch=yhetil.org@gnu.org>)
	for <larch@yhetil.org>; Tue, 18 May 2021 13:58:40 +0000
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by aspmx1.migadu.com (Postfix) with ESMTPS id A5389132A5
	for <larch@yhetil.org>; Tue, 18 May 2021 15:58:39 +0200 (CEST)
Received: from localhost ([::1]:41668 helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <emacs-orgmode-bounces+larch=yhetil.org@gnu.org>)
	id 1lj0F3-0001vS-CN
	for larch@yhetil.org; Tue, 18 May 2021 09:58:37 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:40850)
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <lennart@karssen.org>)
 id 1lj0EK-0001Uw-ER
 for emacs-orgmode@gnu.org; Tue, 18 May 2021 09:57:52 -0400
Received: from se08.route25.eu ([2a00:f10:305:0:1c00:d8ff:fe00:461]:39614)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <lennart@karssen.org>)
 id 1lj0EH-0000IW-DT
 for emacs-orgmode@gnu.org; Tue, 18 May 2021 09:57:51 -0400
To: emacs-orgmode@gnu.org
From: "Lennart C. Karssen" <lennart@karssen.org>
Subject: Global variables in Org mode document with source blocks
Message-ID: <56b14034-f6c4-0528-9235-e0fb9f3f1f28@karssen.org>
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
MIME-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha256;
 protocol="application/pgp-signature";
 boundary="f1rXgcoxuzc2lpV7bCRhlmwIoVlt06Kon"
X-Originating-IP: 185.87.185.80
X-SpamExperts-Domain: out.pcextreme.nl
X-SpamExperts-Username: 185.87.185.80
X-SpamExperts-Outgoing-Class: ham
X-SpamExperts-Outgoing-Evidence: Combined (0.07)
X-Recommended-Action: accept
X-Filter-ID: Pt3MvcO5N4iKaDQ5O6lkdGlMVN6RH8bjRMzItlySaT+WxKTZiywj9AklDI8oHoCvPUtbdvnXkggZ
 3YnVId/Y5jcf0yeVQAvfjHznO7+bT5xiExUbNqvmdkLSOzf1W2Y3z8hkeSqZT0W1YMl0fRDa99cV
 PSoHm0W/3adFfiYl2nuRVaB3ql/iprYdqYRoVpRJ/T4GcPvCLvSpAEEGy7kYxjA4xaKs5cOgbpQu
 MACSpuI/PGDCiu3095bjBHXzclDE1rCfiPnFQ62EmpR+p6i+3689jJvJeHY9KTDbWRQ4iAW96vZx
 eRX7QhOvO6I4yEpR/74zHSqk6CcHzqoCKT+E5sE95bF8tPKjnaWlQ6fjTEeg4CZvTGBeutAohO1y
 UnDCPEg+PVRTiaxPY52n0Pp/86b+Sk5ZBXUgt9/X6plqv8Jl041btgY00t8ZwQGEpPrujd2/KNn9
 7NO2ZQWjyOEIHHU8K0rkb5kkiJbpUX9a4LlQef6Ceaw0tyEeHKZjklTreHL+whhAdKuW1jHRpIte
 tiimkcXcta5lg1BBHrfG9sLNASrPyqZ3YL9752K6v1pQD1e76szsWvBsaS+KViusBg4TfS2su/by
 ymSuqTyxp/ZExDyRiioQmvGTre37mWh0chGFHjQ6q190o7vmaHflcz6s7q3bZAOf0deReKYTnwJK
 C5XROoL23kHH2wGTQk+55tgw+rYwOoN5HTkdx2ADIgbAWeAgFOAXeOAXC+6jSRofgDlU9aIy2kxs
 ++BRV1Ye/SO94N/2SEEH7linr52fw9t+dQYE6xb0bC8E6RbAl1lf989yzIDy4tL2VyWAOf4Nx0C7
 ap1rwdExel9Nw57C9Xc03RHaXiBkAkVPQUIiVhyIyhaI671I4yi7MsEJJOHq7D8P7T4kN34Qrsqz
 V6w0JtnCh+u5TWv2J3COXoYubUFUVV/Or0ckJwrCLS3hLRo9Lzq8YQckJCgF8t/UqHuNWPq0IHVu
 jeZF2q5itXfdJY3H3mAIzR4qjfQIpNkr/3MciY+iEA53XaTEyq4Z4owzgvFgOSC6z8JuvgZ3vw7+
 3ndO9mtZi+7FQPqiPJrRGnvM8OG+Gw2j+q26ukuKZLjzyw==
X-Report-Abuse-To: spam@semaster01.route25.eu
Received-SPF: pass client-ip=2a00:f10:305:0:1c00:d8ff:fe00:461;
 envelope-from=lennart@karssen.org; helo=se08.route25.eu
X-Spam_score_int: -18
X-Spam_score: -1.9
X-Spam_bar: -
X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-BeenThere: emacs-orgmode@gnu.org
X-Mailman-Version: 2.1.23
Precedence: list
List-Id: "General discussions about Org-mode." <emacs-orgmode.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/emacs-orgmode>,
 <mailto:emacs-orgmode-request@gnu.org?subject=unsubscribe>
List-Archive: <https://lists.gnu.org/archive/html/emacs-orgmode>
List-Post: <mailto:emacs-orgmode@gnu.org>
List-Help: <mailto:emacs-orgmode-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/emacs-orgmode>,
 <mailto:emacs-orgmode-request@gnu.org?subject=subscribe>
Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org
Sender: "Emacs-orgmode" <emacs-orgmode-bounces+larch=yhetil.org@gnu.org>
X-Migadu-Flow: FLOW_IN
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org;
	s=key1; t=1621346319;
	h=from:from:sender:sender:reply-to:subject:subject:date:date:
	 message-id:message-id:to:to:cc:mime-version:mime-version:
	 content-type:content-type:list-id:list-help:list-unsubscribe:
	 list-subscribe:list-post; bh=D0eY6KwmZu/2h4gPBn7ZFvIpZuBgsRMP76jWdKILsaw=;
	b=eUmYFLyhHbJARcO/EGFhreKa5MdSL4Zio/ueGFhcCb5dbVjgjcmGkHGF+c9BroP2gfAw+m
	AEajqy1sy6ItFl9GMjScObjXFlpfK/sTjHZp8+HHxiJAxFat6f5Fd+UAzXQS+sXD9WwPH8
	s2d3Tk7DDmAZMpBGqSz6hRYmeoxrGJdZCRIkH8KBUFMd6qoORBuYLXxnN2Zezr7dn7udN0
	Hcrs7OSXe3zIlo2gBkpzye0YdsvOs8/lqyVX3/iYDKmb1KO8ruxexgcdukoEU5ocIAsHuf
	kJKEMnOejcDjmaec6m9MVKM+UjOLia2LLNPnWWS+px4Z9zwQ4AQoTQekQ+AOQg==
ARC-Seal: i=1; s=key1; d=yhetil.org; t=1621346319; a=rsa-sha256; cv=none;
	b=f6LqoWFR3q/ZPpUsILbM4lDRiGJ5SlI40I2HvDsTsY2kHjD0I673hjip+az+vx8ShY6Xjf
	2Yks85aUdrrwZn1LBydXa35klFL4eCrwmotD0K0eWViWxQ2vmXl4jRLAQAkfhnKrrgMK+h
	KjL9AxJbxOwhOA1jnxAh6tohBLbYw4IGw8mDTu300588ib7kKOwGhuWPsH0e368QFQX651
	Qyz9+9V9j5uSYU9jrgvxKRo8AejaorBxTwepX5R9iL+XxQd0hdi09QxobSeWH8p+B10in/
	WtwdGoU2nA1WsXm7WVJESCSkBcVSAFDFFeTBc9RGnCgvqvQc87Eh3/69vCiDgQ==
ARC-Authentication-Results: i=1;
	aspmx1.migadu.com;
	dkim=none;
	spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org
X-Migadu-Spam-Score: -4.54
Authentication-Results: aspmx1.migadu.com;
	dkim=none;
	dmarc=none;
	spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org
X-Migadu-Queue-Id: A5389132A5
X-Spam-Score: -4.54
X-Migadu-Scanner: scn0.migadu.com
X-TUID: FAu+0C0lfTtv

This is an OpenPGP/MIME signed message (RFC 4880 and 3156)
--f1rXgcoxuzc2lpV7bCRhlmwIoVlt06Kon
Content-Type: multipart/mixed; boundary="c2rOWN3kM6qAoPyYEA1ZIUHDRq2DJYS02";
 protected-headers="v1"
From: "Lennart C. Karssen" <lennart@karssen.org>
To: emacs-orgmode@gnu.org
Message-ID: <56b14034-f6c4-0528-9235-e0fb9f3f1f28@karssen.org>
Subject: Global variables in Org mode document with source blocks

--c2rOWN3kM6qAoPyYEA1ZIUHDRq2DJYS02
Content-Type: text/plain; charset=utf-8
Content-Language: en-GB
Content-Transfer-Encoding: quoted-printable

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 =3D 0, I would like to do:=


#+header :var nFailed=3DnrChecksFailed :var someData=3DsomeData
#+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=3DnrChecksFailed
#+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.

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

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


--c2rOWN3kM6qAoPyYEA1ZIUHDRq2DJYS02--

--f1rXgcoxuzc2lpV7bCRhlmwIoVlt06Kon
Content-Type: application/pgp-signature; name="OpenPGP_signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="OpenPGP_signature"

-----BEGIN PGP SIGNATURE-----

wnsEABEIACMWIQQyBENSov4Y8H9uObIgAxQL2pzVCQUCYKPHyQUDAAAAAAAKCRAgAxQL2pzVCQOA
AP9lUCIYlGMBx10OvLXmavq7vAzVLKjmDmIjwgYPkQx2vAD+NoUjOfq4sN31ED+/xjWXMeV6B5bB
TIx7uX+TOS7Nwu8=
=5t0u
-----END PGP SIGNATURE-----

--f1rXgcoxuzc2lpV7bCRhlmwIoVlt06Kon--