Skip to content

Commit b919c54

Browse files
committedApr 27, 2024·
Merge branch 'master' into interactive-tbl-hidden-col-fix
2 parents a07d2ec + 620f94a commit b919c54

33 files changed

+488
-144
lines changed
 

‎R/datasets.R

+92-34
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,6 @@
707707
#'
708708
"illness"
709709

710-
711710
#' Reaction rates for gas-phase atmospheric reactions of organic compounds
712711
#'
713712
#' @description
@@ -723,18 +722,18 @@
723722
#' chlorine (Cl) atoms.
724723
#'
725724
#' This compilation of rate constant (*k*) data as contains the values for rate
726-
#' constants at 298 K (in units of cm^3 molecules^–1 s^–1) as well as parameters
727-
#' that allow for the calculation of rate constants at different temperatures
728-
#' (the temperature dependence parameters: `A`, `B`, and `n`). Uncertainty
729-
#' values/factors and temperature limits are also provided here where
730-
#' information is available.
725+
#' constants at 298 K (in units of `cm^3 molecules^–1 s^–1`) as well as
726+
#' parameters that allow for the calculation of rate constants at different
727+
#' temperatures (the temperature dependence parameters: `A`, `B`, and `n`).
728+
#' Uncertainty values/factors and temperature limits are also provided here
729+
#' where information is available.
731730
#'
732731
#' @format A tibble with 1,683 rows and 39 variables:
733732
#' \describe{
734733
#' \item{compd_name}{The name of the primary compound undergoing
735734
#' reaction with OH, ozone, NO3, or Cl.}
736735
#' \item{cmpd_mwt}{The molecular weight of the compound in units of g/mol.}
737-
#' \item{cmpd_formula}{The atomic formula of the compound.}
736+
#' \item{cmpd_formula}{The chemical formula of the compound.}
738737
#' \item{cmpd_type}{The category of compounds that the `compd_name` falls
739738
#' under.}
740739
#' \item{cmpd_smiles}{The SMILES (simplified molecular-input line-entry system)
@@ -744,51 +743,51 @@
744743
#' \item{cmpd_inchikey}{The InChIKey, which is a hashed InChI value, has a fixed
745744
#' length of 27 characters. These values can be used to more easily perform
746745
#' database searches of chemical compounds.}
747-
#' \item{oh_k298}{Rate constant at 298 K for OH reactions.}
748-
#' \item{oh_uncert}{Uncertainty as a percentage for certain OH reactions.}
749-
#' \item{oh_u_fac}{Uncertainty as a plus/minus difference for certain OH
746+
#' \item{OH_k298}{Rate constant at 298 K for OH reactions.}
747+
#' \item{OH_uncert}{Uncertainty as a percentage for certain OH reactions.}
748+
#' \item{OH_u_fac}{Uncertainty as a plus/minus difference for certain OH
750749
#' reactions.}
751-
#' \item{oh_a, oh_b, oh_n}{Extended temperature dependence parameters for
750+
#' \item{OH_a, OH_b, OH_n}{Extended temperature dependence parameters for
752751
#' bimolecular OH reactions, to be used in the Arrhenius expression:
753752
#' `k(T)=A exp(-B/T) (T/300)^n`. In that, `A` is expressed as
754753
#' cm^3 molecules^-1 s^-1, `B` is in units of K, and `n` is dimensionless. Any
755754
#' `NA` values indicate that data is not available.}
756-
#' \item{oh_t_low, oh_t_high}{The low and high temperature boundaries (in units
757-
#' of K) for which the `oh_a`, `oh_b`, and `oh_n` parameters are valid.}
758-
#' \item{o3_k298}{Rate constant at 298 K for ozone reactions.}
759-
#' \item{o3_uncert}{Uncertainty as a percentage for certain ozone reactions.}
760-
#' \item{o3_u_fac}{Uncertainty as a plus/minus difference for certain ozone
755+
#' \item{OH_t_low, OH_t_high}{The low and high temperature boundaries (in units
756+
#' of K) for which the `OH_a`, `OH_b`, and `OH_n` parameters are valid.}
757+
#' \item{O3_k298}{Rate constant at 298 K for ozone reactions.}
758+
#' \item{O3_uncert}{Uncertainty as a percentage for certain ozone reactions.}
759+
#' \item{O3_u_fac}{Uncertainty as a plus/minus difference for certain ozone
761760
#' reactions.}
762-
#' \item{o3_a, o3_b, o3_n}{Extended temperature dependence parameters for
761+
#' \item{O3_a, O3_b, O3_n}{Extended temperature dependence parameters for
763762
#' bimolecular ozone reactions, to be used in the Arrhenius expression:
764763
#' `k(T)=A exp(-B/T) (T/300)^n`. In that, `A` is expressed as
765764
#' cm^3 molecules^-1 s^-1, `B` is in units of K, and `n` is dimensionless. Any
766765
#' `NA` values indicate that data is not available.}
767-
#' \item{o3_t_low, o3_t_high}{The low and high temperature boundaries (in units
768-
#' of K) for which the `o3_a`, `o3_b`, and `o3_n` parameters are valid.}
769-
#' \item{no3_k298}{Rate constant at 298 K for NO3 reactions.}
770-
#' \item{no3_uncert}{Uncertainty as a percentage for certain NO3 reactions.}
771-
#' \item{no3_u_fac}{Uncertainty as a plus/minus difference for certain NO3
766+
#' \item{O3_t_low, O3_t_high}{The low and high temperature boundaries (in units
767+
#' of K) for which the `O3_a`, `O3_b`, and `O3_n` parameters are valid.}
768+
#' \item{NO3_k298}{Rate constant at 298 K for NO3 reactions.}
769+
#' \item{NO3_uncert}{Uncertainty as a percentage for certain NO3 reactions.}
770+
#' \item{NO3_u_fac}{Uncertainty as a plus/minus difference for certain NO3
772771
#' reactions.}
773-
#' \item{no3_a, no3_b, no3_n}{Extended temperature dependence parameters for
772+
#' \item{NO3_a, NO3_b, NO3_n}{Extended temperature dependence parameters for
774773
#' bimolecular NO3 reactions, to be used in the Arrhenius expression:
775774
#' `k(T)=A exp(-B/T) (T/300)^n`. In that, `A` is expressed as
776775
#' cm^3 molecules^-1 s^-1, `B` is in units of K, and `n` is dimensionless. Any
777776
#' `NA` values indicate that data is not available.}
778-
#' \item{no3_t_low, no3_t_high}{The low and high temperature boundaries (in
779-
#' units of K) for which the `no3_a`, `no3_b`, and `no3_n` parameters are
777+
#' \item{NO3_t_low, NO3_t_high}{The low and high temperature boundaries (in
778+
#' units of K) for which the `NO3_a`, `NO3_b`, and `NO3_n` parameters are
780779
#' valid.}
781-
#' \item{cl_k298}{Rate constant at 298 K for Cl reactions.}
782-
#' \item{cl_uncert}{Uncertainty as a percentage for certain Cl reactions.}
783-
#' \item{cl_u_fac}{Uncertainty as a plus/minus difference for certain Cl
780+
#' \item{Cl_k298}{Rate constant at 298 K for Cl reactions.}
781+
#' \item{Cl_uncert}{Uncertainty as a percentage for certain Cl reactions.}
782+
#' \item{Cl_u_fac}{Uncertainty as a plus/minus difference for certain Cl
784783
#' reactions.}
785-
#' \item{cl_a, cl_b, cl_n}{Extended temperature dependence parameters for
784+
#' \item{Cl_a, Cl_b, Cl_n}{Extended temperature dependence parameters for
786785
#' bimolecular Cl reactions, to be used in the Arrhenius expression:
787786
#' `k(T)=A exp(-B/T) (T/300)^n`. In that, `A` is expressed as
788787
#' cm^3 molecules^-1 s^-1, `B` is in units of K, and `n` is dimensionless. Any
789788
#' `NA` values indicate that data is not available.}
790-
#' \item{cl_t_low, cl_t_high}{The low and high temperature boundaries (in units
791-
#' of K) for which the `cl_a`, `cl_b`, and `cl_n` parameters are valid.}
789+
#' \item{Cl_t_low, Cl_t_high}{The low and high temperature boundaries (in units
790+
#' of K) for which the `Cl_a`, `Cl_b`, and `Cl_n` parameters are valid.}
792791
#' }
793792
#'
794793
#' @section Examples:
@@ -808,10 +807,69 @@
808807
#' }}
809808
#'
810809
#' @section Dataset Introduced:
811-
#' *in development*
810+
#' *In Development*
812811
#'
813812
"reactions"
814813

814+
#' Data on photolysis rates for gas-phase organic compounds
815+
#'
816+
#' @description
817+
#'
818+
#' The `photolysis` dataset contains numerical values for describing the
819+
#' photolytic degradation pathways of 25 compounds of relevance in atmospheric
820+
#' chemistry. Many volatile organic compounds (VOCs) are emitted in substantial
821+
#' quantities from both biogenic and anthropogenic sources, and they can have a
822+
#' major influence on the chemistry of the lower atmosphere. A portion of these
823+
#' can be transformed into other VOCs via the energy provided from light.
824+
#'
825+
#' In order to realistically predict the composition of the atmosphere and how
826+
#' it evolves over time, we need accurate estimates of photolysis rates. The
827+
#' data provided here in `photolysis` allows for computations of photolysis
828+
#' rates (*J*, having units of `s^-1`) as a function of the solar zenith angle
829+
#' (SZA). Having such values is essential when deploying atmospheric chemistry
830+
#' models.
831+
#'
832+
#' @format A tibble with 34 rows and 10 variables:
833+
#' \describe{
834+
#' \item{compd_name}{The name of the primary compound undergoing photolysis.}
835+
#' \item{cmpd_formula}{The chemical formula of the compound.}
836+
#' \item{products}{A product pathway for the photolysis of the compound.}
837+
#' \item{type}{The type of organic compound undergoing photolysis.}
838+
#' \item{l, m, n}{The parameter values given in the `l`, `m`, and `n` columns
839+
#' can be used to calculate the photolysis rate (*J*) as a function of the
840+
#' solar zenith angle (*X*, in radians) through the expression:
841+
#' `J = l * cos(X)^m * exp(-n * sec(X))`.}
842+
#' \item{quantum_yield}{In the context of photolysis reactions, this is the
843+
#' efficiency of a given photolytic reaction. In other words, it's the number of
844+
#' product molecules formed over the number of photons absorbed.}
845+
#' \item{wavelength_nm, sigma_298_cm2}{The `wavelength_nm` and `sigma_298_cm2`
846+
#' columns provide photoabsorption data for the compound undergoing photolysis.
847+
#' The values in `wavelength_nm` provide the wavelength of light in nanometer
848+
#' units; the `sigma_298_cm2` values are paired with the `wavelength_nm` values
849+
#' and they are in units of `cm^2 molecule^-1`.}
850+
#' }
851+
#'
852+
#' @section Examples:
853+
#'
854+
#' Here is a glimpse at the data available in `photolysis`.
855+
#'
856+
#' ```{r}
857+
#' dplyr::glimpse(photolysis)
858+
#' ```
859+
#'
860+
#' @family datasets
861+
#' @section Dataset ID and Badge:
862+
#' DATA-12
863+
#'
864+
#' \if{html}{\out{
865+
#' `r data_get_image_tag(file = "dataset_photolysis.png")`
866+
#' }}
867+
#'
868+
#' @section Dataset Introduced:
869+
#' *In Development*
870+
#'
871+
"photolysis"
872+
815873
#' An ADSL-flavored clinical trial toy dataset
816874
#'
817875
#' @description
@@ -871,7 +929,7 @@
871929
#'
872930
#' @family datasets
873931
#' @section Dataset ID and Badge:
874-
#' DATA-12
932+
#' DATA-13
875933
#'
876934
#' \if{html}{\out{
877935
#' `r data_get_image_tag(file = "dataset_rx_adsl.png")`
@@ -944,7 +1002,7 @@
9441002
#'
9451003
#' @family datasets
9461004
#' @section Dataset ID and Badge:
947-
#' DATA-13
1005+
#' DATA-14
9481006
#'
9491007
#' \if{html}{\out{
9501008
#' `r data_get_image_tag(file = "dataset_rx_addv.png")`

‎R/format_data.R

+57-10
Original file line numberDiff line numberDiff line change
@@ -8687,29 +8687,76 @@ fmt_units <- function(
86878687
#' dplyr::filter(grepl("^1-", cmpd_name)) |>
86888688
#' dplyr::select(cmpd_name, cmpd_formula, ends_with("k298")) |>
86898689
#' gt() |>
8690-
#' sub_missing() |>
8690+
#' tab_header(title = "Gas-phase reactions of selected terminal alkenes") |>
8691+
#' tab_spanner(
8692+
#' label = "Reaction Rate Constant at 298 K",
8693+
#' columns = ends_with("k298")
8694+
#' ) |>
86918695
#' fmt_chem(columns = cmpd_formula) |>
86928696
#' fmt_scientific() |>
8697+
#' sub_missing() |>
86938698
#' cols_label(
86948699
#' cmpd_name = "Alkene",
86958700
#' cmpd_formula = "Formula",
8696-
#' oh_k298 = "OH",
8697-
#' o3_k298 = "{{%O3%}}",
8698-
#' no3_k298 = "{{%NO3%}}",
8699-
#' cl_k298 = "Cl"
8701+
#' OH_k298 = "OH",
8702+
#' O3_k298 = "{{%O3%}}",
8703+
#' NO3_k298 = "{{%NO3%}}",
8704+
#' Cl_k298 = "Cl"
87008705
#' ) |>
8701-
#' tab_spanner(
8702-
#' label = "Reaction Rate Constant at 298 K",
8703-
#' columns = ends_with("k298")
8704-
#' ) |>
8705-
#' tab_header(title = "Gas-phase reactions of selected terminal alkenes") |>
87068706
#' opt_align_table_header(align = "left")
87078707
#' ```
87088708
#'
87098709
#' \if{html}{\out{
87108710
#' `r man_get_image_tag(file = "man_fmt_chem_1.png")`
87118711
#' }}
87128712
#'
8713+
#' Taking just a few rows from the [`photolysis`] dataset, let's and create a
8714+
#' new **gt** table. The `cmpd_formula` and `products` columns both contain
8715+
#' text in chemistry notation (the first has compounds, and the second column
8716+
#' has the products of photolysis reactions). These columns will be formatting
8717+
#' by the `fmt_chem()` function. The compound formulas will be merged with the
8718+
#' compound names via the [cols_merge()] function.
8719+
#'
8720+
#' ```r
8721+
#' photolysis %>%
8722+
#' dplyr::filter(cmpd_name %in% c(
8723+
#' "hydrogen peroxide", "nitrous acid",
8724+
#' "nitric acid", "acetaldehyde",
8725+
#' "methyl peroxide", "methyl nitrate",
8726+
#' "ethyl nitrate", "isopropyl nitrate"
8727+
#' )) |>
8728+
#' dplyr::select(-c(l, m, n, quantum_yield, type)) |>
8729+
#' gt() |>
8730+
#' tab_header(title = "Photolysis pathways of selected VOCs") |>
8731+
#' fmt_chem(columns = c(cmpd_formula, products)) |>
8732+
#' cols_nanoplot(
8733+
#' columns = sigma_298_cm2,
8734+
#' columns_x_vals = wavelength_nm,
8735+
#' expand_x = c(200, 400),
8736+
#' new_col_name = "cross_section",
8737+
#' new_col_label = "Absorption Cross Section",
8738+
#' options = nanoplot_options(
8739+
#' show_data_points = FALSE,
8740+
#' data_line_stroke_width = 4,
8741+
#' data_line_stroke_color = "black",
8742+
#' show_data_area = FALSE
8743+
#' )
8744+
#' ) |>
8745+
#' cols_merge(
8746+
#' columns = c(cmpd_name, cmpd_formula),
8747+
#' pattern = "{1}, {2}"
8748+
#' ) |>
8749+
#' cols_label(
8750+
#' cmpd_name = "Compound",
8751+
#' products = "Products"
8752+
#' ) |>
8753+
#' opt_align_table_header(align = "left")
8754+
#' ```
8755+
#'
8756+
#' \if{html}{\out{
8757+
#' `r man_get_image_tag(file = "man_fmt_chem_2.png")`
8758+
#' }}
8759+
#'
87138760
#' @family data formatting functions
87148761
#' @section Function ID:
87158762
#' 3-19

‎R/utils_units.R

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ define_units <- function(units_notation, is_chemical_formula = FALSE) {
3737

3838
chem_text <- gsub(".*(\\%.*\\%).*", "\\1", input)
3939
chem_input <- gsub("^%|%$", "", chem_text)
40+
chem_input <- gsub("\\(\\^([^\\)])", "( ^\\1", chem_input)
4041

4142
# Replace single bonds
4243
for (i in seq(1, 10)) {

‎data-raw/11-reactions.R

+13-15
Original file line numberDiff line numberDiff line change
@@ -80,24 +80,22 @@ reactions <-
8080
) %>%
8181
dplyr::mutate(across(starts_with("feat"), ~ tidyr::replace_na(.x, 0)))
8282

83-
colnames(reactions) <- tolower(colnames(reactions))
84-
8583
reactions <-
8684
reactions %>%
87-
dplyr::mutate(oh_uncert = case_when(
88-
!is.na(oh_unc) ~ as.numeric(sub("%", "", oh_unc)) / 100,
85+
dplyr::mutate(OH_uncert = case_when(
86+
!is.na(OH_unc) ~ as.numeric(sub("%", "", OH_unc)) / 100,
8987
TRUE ~ NA_real_
9088
)) %>%
91-
dplyr::mutate(o3_uncert = case_when(
92-
!is.na(o3_unc) ~ as.numeric(sub("%", "", o3_unc)) / 100,
89+
dplyr::mutate(O3_uncert = case_when(
90+
!is.na(O3_unc) ~ as.numeric(sub("%", "", O3_unc)) / 100,
9391
TRUE ~ NA_real_
9492
)) %>%
95-
dplyr::mutate(no3_uncert = case_when(
96-
!is.na(no3_unc) ~ as.numeric(sub("%", "", no3_unc)) / 100,
93+
dplyr::mutate(NO3_uncert = case_when(
94+
!is.na(NO3_unc) ~ as.numeric(sub("%", "", NO3_unc)) / 100,
9795
TRUE ~ NA_real_
9896
)) %>%
99-
dplyr::mutate(cl_uncert = case_when(
100-
!is.na(cl_unc) ~ as.numeric(sub("%", "", cl_unc)) / 100,
97+
dplyr::mutate(Cl_uncert = case_when(
98+
!is.na(Cl_unc) ~ as.numeric(sub("%", "", Cl_unc)) / 100,
10199
TRUE ~ NA_real_
102100
)) %>%
103101
dplyr::select(-ends_with("unc"))
@@ -195,12 +193,12 @@ compound_types <-
195193

196194
reactions <-
197195
reactions %>%
198-
dplyr::inner_join(compound_types) %>%
196+
dplyr::inner_join(compound_types, by = c("cmpd_type" = "cmpd_type")) %>%
199197
dplyr::relocate(cmpd_desc, .after = cmpd_struct_fml) %>%
200-
dplyr::relocate(oh_uncert, .before = oh_u_fac) %>%
201-
dplyr::relocate(o3_uncert, .before = o3_u_fac) %>%
202-
dplyr::relocate(no3_uncert, .before = no3_u_fac) %>%
203-
dplyr::relocate(cl_uncert, .before = cl_u_fac) %>%
198+
dplyr::relocate(OH_uncert, .before = OH_u_fac) %>%
199+
dplyr::relocate(O3_uncert, .before = O3_u_fac) %>%
200+
dplyr::relocate(NO3_uncert, .before = NO3_u_fac) %>%
201+
dplyr::relocate(Cl_uncert, .before = Cl_u_fac) %>%
204202
dplyr::select(-cmpd_type, -cmpd_no, -cmpd_struct_fml, -starts_with("feat")) %>%
205203
dplyr::rename(cmpd_name = cmpd_primary_name) %>%
206204
dplyr::rename(cmpd_formula = cmpd_atomic_fml) %>%

‎data-raw/12-photolysis.R

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
library(tidyverse)
2+
3+
photolysis <-
4+
readr::read_csv(
5+
file = "data-raw/photolysis.csv",
6+
col_types =
7+
cols(
8+
cmpd_name = col_character(),
9+
cmpd_formula = col_character(),
10+
products = col_character(),
11+
type = col_character(),
12+
l = col_double(),
13+
m = col_double(),
14+
n = col_double(),
15+
quantum_yield = col_double(),
16+
wavelength_nm = col_character(),
17+
sigma_298_cm2 = col_character()
18+
)
19+
)
20+
File renamed without changes.

‎data-raw/photolysis.csv

+35
Large diffs are not rendered by default.

‎data-raw/zz_process_datasets.R

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ source("data-raw/08-metro.R")
1111
source("data-raw/09-constants.R")
1212
source("data-raw/10-illness.R")
1313
source("data-raw/11-reactions.R")
14-
source("data-raw/12-gt_clinical.R")
14+
source("data-raw/12-photolysis.R")
15+
source("data-raw/13-gt_clinical.R")
1516

1617
# Create external datasets
1718
usethis::use_data(
1819
countrypops, sza, gtcars, sp500,
1920
pizzaplace, exibble, towny, metro,
2021
constants, illness, reactions,
21-
rx_adsl, rx_addv,
22+
photolysis, rx_adsl, rx_addv,
2223
internal = FALSE, overwrite = TRUE
2324
)

‎data/photolysis.rda

10.2 KB
Binary file not shown.

‎data/reactions.rda

12 Bytes
Binary file not shown.

‎images/dataset_constants.svg

+1-2
Loading

‎images/dataset_countrypops.svg

+1-2
Loading

‎images/dataset_metro.svg

+1-2
Loading

‎images/dataset_photolysis.png

69.2 KB
Loading

‎images/dataset_photolysis.svg

+30
Loading

‎images/dataset_reactions.svg

+1-2
Loading

‎images/man_fmt_chem_2.png

159 KB
Loading

‎man/constants.Rd

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎man/countrypops.Rd

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎man/exibble.Rd

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎man/fmt_chem.Rd

+56-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎man/gtcars.Rd

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎man/illness.Rd

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎man/metro.Rd

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎man/photolysis.Rd

+98
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎man/pizzaplace.Rd

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎man/reactions.Rd

+64-63
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎man/rx_addv.Rd

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎man/rx_adsl.Rd

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎man/sp500.Rd

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎man/sza.Rd

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎man/towny.Rd

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pkgdown/_pkgdown.yml

+1
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ reference:
372372
- constants
373373
- illness
374374
- reactions
375+
- photolysis
375376
- rx_adsl
376377
- rx_addv
377378

0 commit comments

Comments
 (0)
Please sign in to comment.