<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/constants-0-0-1/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://www.enchufa2.es/archives/constants-0-0-1.html"> R – Enchufa2</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>The new <a rel="nofollow" href="https://cran.r-project.org/package=constants" target="_blank"><code>constants</code></a> package is available on CRAN. This small package provides the CODATA 2014 internationally recommended values of the fundamental physical constants (universal, electromagnetic, physicochemical, atomic…), provided as symbols for direct use within the R language. Optionally, the values with errors and/or the values with units are also provided if the <a rel="nofollow" href="https://cran.r-project.org/package=errors" target="_blank"><code>errors</code></a> and/or the <a rel="nofollow" href="https://cran.r-project.org/package=units" target="_blank"><code>units</code></a> packages are installed as well.</p>
<p>But, what is CODATA? The <a rel="nofollow" href="http://www.codata.org/" target="_blank">Committee on Data for Science and Technology</a> (CODATA) is an interdisciplinary committee of the International Council for Science. The <a rel="nofollow" href="http://www.codata.org/committees-and-groups/fundamental-physical-constants" target="_blank">Task Group on Fundamental Constants</a> periodically provides the internationally accepted set of values of the fundamental physical constants. The version currently in force is the “2014 CODATA”, published on 25 June 2015.</p>
<p>This package wraps the <code>codata</code> dataset, defines unique symbols for each one of the 237 constants, and provides them enclosed in three sets of symbols: <code>syms</code>, <code>syms_with_errors</code> and <code>syms_with_units</code>.</p>
<pre><code><span>library</span><span>(</span><span>constants</span><span>)</span>

<span># the speed of light</span>
<span>with</span><span>(</span><span>syms</span>, <span>c0</span><span>)</span></code></pre>
<pre><code>## [1] 299792458</code></pre>
<pre><code><span># explore which constants are available</span>
<span>lookup</span><span>(</span><span>&quot;planck constant&quot;</span>, <span>ignore.case</span><span>=</span><span>TRUE</span><span>)</span></code></pre>
<pre><code>##                  quantity  symbol            value      unit
## 7         Planck constant       h  6.626070040e-34       J s
## 8         Planck constant    h_eV  4.135667662e-15      eV s
## 9         Planck constant    hbar         h/(2*pi)       J s
## 10        Planck constant hbar_eV      h_eV/(2*pi)      eV s
## 11        Planck constant hbar.c0      197.3269788    MeV fm
## 212 molar Planck constant    Na.h 3.9903127110e-10 J s mol-1
## 213 molar Planck constant Na.h.c0   0.119626565582 J m mol-1
##     rel_uncertainty            type
## 7           1.2e-08       universal
## 8           6.1e-09       universal
## 9           1.2e-08       universal
## 10          6.1e-09       universal
## 11          6.1e-09       universal
## 212         4.5e-10 physicochemical
## 213         4.5e-10 physicochemical</code></pre>
<pre><code><span># symbols can also be attached to the search path</span>
<span>attach</span><span>(</span><span>syms</span><span>)</span>
<span># the Planck constant</span>
<span>hbar</span></code></pre>
<pre><code>## [1] 1.054572e-34</code></pre>
<p>If the <code>errors</code>/<code>units</code> package is installed in your system, constants with errors/units are available:</p>
<pre><code><span>attach</span><span>(</span><span>syms_with_errors</span><span>)</span>
<span># the Planck constant with error</span>
<span>hbar</span></code></pre>
<pre><code>## 1.05457180(1)e-34</code></pre>
<pre><code><span>attach</span><span>(</span><span>syms_with_units</span><span>)</span>
<span># the Planck constant with units</span>
<span>hbar</span></code></pre>
<pre><code>## 1.054572e-34 J*s</code></pre>
<p>The dataset is available for lazy loading:</p>
<pre><code><span>data</span><span>(</span><span>codata</span><span>)</span>
<span>head</span><span>(</span><span>codata</span><span>)</span></code></pre>
<pre><code>##                             quantity    symbol        value        unit
## 1           speed of light in vacuum        c0    299792458       m s-1
## 2                  magnetic constant       mu0    4*pi*1e-7       N A-2
## 3                  electric constant  epsilon0 1/(mu0*c0^2)       F m-1
## 4 characteristic impedance of vacuum        Z0       mu0*c0           Ω
## 5  Newtonian constant of gravitation         G  6.67408e-11 m3 kg-1 s-2
## 6  Newtonian constant of gravitation G_hbar.c0  6.70861e-39    GeV-2 c4
##   rel_uncertainty      type
## 1         0.0e+00 universal
## 2         0.0e+00 universal
## 3         0.0e+00 universal
## 4         0.0e+00 universal
## 5         4.7e-05 universal
## 6         4.7e-05 universal</code></pre>
<pre><code><span>dplyr</span><span>:</span><span>:</span><span>count</span><span>(</span><span>codata</span>, <span>type</span>, <span>sort</span><span>=</span><span>TRUE</span><span>)</span></code></pre>
<pre><code>## # A tibble: 15 x 2
##                          type     n
##                         </code></pre>