9  Namespaces

Namespaces are alternate representations of a limited set of data column metadata.

9.1 Specification

For example, if I have a column called WT which is the baseline subject weight. I might assign a short name of called weight; this is sufficient in most cases.

WT: 
  short: weight

However, I want some flexibility to call the column baseline weight in other circumstances. We can make both options available by creating namespaces for the alternatives.

WT: 
  short: weight
  short.full: baseline weight

Here, we list short (the default or in the base namespace) and short.full which is how we put an alternate version of short that becomes available when we change to the full namespace.

9.2 Changing namespaces

Let’s load this fragment to see how it works

spec <- ys_load("inline/namespace1.yml")

By default we get the base namespace

spec
 name info unit short  source
 WT   ---  .    weight .     

We can look at the available namespaces in this object

ys_namespace(spec)

And then switch to the full namespace

spec_full <- ys_namespace(spec, "full")

Now we see the alternate version

ys_get_short(spec_full)
$WT
[1] "baseline weight"

9.3 Special tex namespace

There is a somewhat special namespace called tex. It operates like other namespaces, but yspec knows to look to see if it is available in certain circumstances.

DV: 
  short: concentration
  unit: microgram/L
  unit.tex: "$\\mu$g/L"

Here, we’ve customized the unit field to include a tex namespace. The units for DV will render with math symbols when included in a TeX document.

When we build a define.pdf document for this data

ys_document(spec, type = "regulatory")

we are using TeX to generate the document. yspec knows to look for the tex namespace and switch to that namespace in that enviroment so the unit for DV will render with the intended math symbols.