Skip to main content

15.3 Using Header Arguments

Org comes with many header arguments common to all languages. New header arguments are added for specific languages as they become available for use in source code blocks. A header argument is specified with an initial colon followed by the argument’s name in lowercase.

Since header arguments can be set in several ways, Org prioritizes them in case of overlaps or conflicts by giving local settings a higher priority. Header values in function calls, for example, override header values from global defaults.

System-wide header arguments​

System-wide values of header arguments can be specified by customizing the org-babel-default-header-args variable, which defaults to the following values:

:session    => "none"
:results => "replace"
:exports => "code"
:cache => "no"
:noweb => "no"

The example below sets β€˜:noweb’ header arguments to β€˜yes’, which makes Org expand β€˜:noweb’ references by default.

(setq org-babel-default-header-args
(cons '(:noweb . "yes")
(assq-delete-all :noweb org-babel-default-header-args)))

Each language can have separate default header arguments by customizing the variable org-babel-default-header-args:<LANG>, where <LANG> is the name of the language. For details, see the language-specific online documentation at https://orgmode.org/worg/org-contrib/babel/.

Header arguments in Org mode properties​

For header arguments applicable to the buffer, use β€˜PROPERTY’ keyword anywhere in the Org file (see Property Syntax).

The following example makes all the R code blocks execute in the same session. Setting β€˜:results’ to β€˜silent’ ignores the results of executions for all blocks, not just R code blocks; no results inserted for any block.

#+PROPERTY: header-args:R  :session *R*
#+PROPERTY: header-args :results silent

Header arguments set through Org’s property drawers (see Property Syntax) apply at the sub-tree level on down. Since these property drawers can appear anywhere in the file hierarchy, Org uses outermost call or source block to resolve the values. Org ignores org-use-property-inheritance setting.

In this example, β€˜:cache’ defaults to β€˜yes’ for all code blocks in the sub-tree.

* sample header
:PROPERTIES:
:header-args: :cache yes
:END:

Properties defined through org-set-property function, bound to C-c C-x p, apply to all active languages. They override properties set in org-babel-default-header-args.

Language-specific header arguments are also read from properties β€˜header-args:<LANG>’ where <LANG> is the language identifier. For example,

* Heading
:PROPERTIES:
:header-args:clojure: :session *clojure-1*
:header-args:R: :session *R*
:END:
** Subheading
:PROPERTIES:
:header-args:clojure: :session *clojure-2*
:END:

would force separate sessions for Clojure blocks in β€˜Heading’ and β€˜Subheading’, but use the same session for all R blocks. Blocks in β€˜Subheading’ inherit settings from β€˜Heading’.

Code block specific header arguments​

Header arguments are most commonly set at the source code block level, on the β€˜#+BEGIN_SRC’ line. Arguments set at this level take precedence over those set in the org-babel-default-header-args variable, and also those set as header properties.

In the following example, setting β€˜:results’ to β€˜silent’ makes it ignore results of the code execution. Setting β€˜:exports’ to β€˜code’ exports only the body of the code block to HTML or LaTeX.

#+NAME: factorial
#+BEGIN_SRC haskell :results silent :exports code :var n=0
fac 0 = 1
fac n = n * fac (n-1)
#+END_SRC

The same header arguments in an inline code block:

src_haskell[:exports both]{fac 5}

Code block header arguments can span multiple lines using β€˜#+HEADER:’ on each line. Note that Org currently accepts the plural spelling of β€˜#+HEADER:’ only as a convenience for backward-compatibility. It may be removed at some point.

Multi-line header arguments on an unnamed code block:

#+HEADER: :var data1=1
#+BEGIN_SRC emacs-lisp :var data2=2
(message "data1:%S, data2:%S" data1 data2)
#+END_SRC

#+RESULTS:
: data1:1, data2:2

Multi-line header arguments on a named code block:

#+NAME: named-block
#+HEADER: :var data=2
#+BEGIN_SRC emacs-lisp
(message "data:%S" data)
#+END_SRC

#+RESULTS: named-block
: data:2

Header arguments in function calls​

Header arguments in function calls are the most specific and override all other settings in case of an overlap. They get the highest priority. Two β€˜#+CALL:’ examples are shown below. For the complete syntax of β€˜CALL’ keyword, see Evaluating Code Blocks.

In this example, β€˜:exports results’ header argument is applied to the evaluation of the β€˜#+CALL:’ line.

#+CALL: factorial(n=5) :exports results

In this example, β€˜:session special’ header argument is applied to the evaluation of β€˜factorial’ code block.

#+CALL: factorial[:session special](n=5)