---
title: "iemiscdata: USEPA East Palestine, Ohio Norfolk Southern Train 32N Cargo List -- Chemical Databases Match"
date: today
date-format: D MMMM YYYY  
author:
  - name: Irucka Embry
    affiliation: 
      - name: EcoC&sup2;S
        city: Nashville
        state: TN
        url: https://www.ecoccs.com
    degrees:
      - EIT
      - ME
lang: en-US
dir: ltr
format:
  pdf:
    pdf-standard: a-3u
    toc: true
    toc-title: Table of Contents
    papersize: letter
    margin-left: 0.79in
    margin-right: 0.79in
    mainfont: FreeSerif
    sansfont: FreeSans
    monofont: FreeMono
    code-line-numbers: true
    syntax-highlighting: kate
    colorlinks: true
    fontsize: 12pt
    author-meta: "Irucka Embry, Eco-Creative Consulting Services, EcoC^2^S"
vignette: >
  %\VignetteIndexEntry{iemiscdata USEPA East Palestine, Ohio Norfolk Southern Train 32N Cargo List -- Chemical Databases Match}
  %\VignetteEngine{quarto::pdf}
  %\VignetteEncoding{UTF-8}
---

\bigskip

# Available Chemical Information

The following provides chemical information from either the chem_wiki or atsdr_tsca_ld50_a data sets from the `chem.databases` R package created by the author for matching chemical substances in the commodities list from the United States Environmental Protection Agency (US EPA) East Palestine, Ohio Norfolk Southern Train 32N Cargo List. The cargo list is one of the data sets in this `iemiscdata` R package also created by the author.  

\medskip

```{r}
#| warning: false
#| message: false
#| tidy: true

install.load::load_package("iemiscdata", "chem.databases", "data.table", "mgsub", "stringi", "pander")
# load needed packages using the load_package function from the install.load package (it is assumed that you have already installed these packages)

# set the pander options
panderOptions("missing", "")


data(norfolk_southern_epoh, package = "iemiscdata")
# from iemiscdata package

data(chem_wiki, package = "chem.databases")
# from chem.databases package

data(atsdr_tsca_ld50_a, package = "chem.databases")
# from chem.databases package



train_commodities <- unique(norfolk_southern_epoh$Commodity)

pander::pander(train_commodities)


# remove items that are not needed

train_commodities <- train_commodities[-c(3, 9, 16:20, 23:26)]


# remove words that are not needed

train_commodities <- mgsub::mgsub(train_commodities, c(", STABILIZED", "COMBUSTIBLE LIQ., NOS", "LUBE OIL", "WAX"), rep("", 4), fixed = TRUE)


# remove parentheses that are not needed

train_commodities <- mgsub::mgsub(train_commodities, c("\\(", "\\)"), rep("", 2), fixed = FALSE)


# remove the beginning and trailing white space

train_commodities <- stringi::stri_trim_both(train_commodities)


# transform the text to sentence case

train_commodities <- stri_trans_totitle(train_commodities, type = "sentence")


# correct the spelling as needed

train_commodities[4] <- "Dipropylene glycol"

train_commodities[9] <- "Polyvinyl chloride"

train_commodities[13] <- "Butyl acrylate"

pander::pander(train_commodities)


# the exact matched chemical names

pander::pander(chem_wiki[`Substance Name` %in% train_commodities])

pander::pander(atsdr_tsca_ld50_a[`Registry Name` %in% train_commodities])


# the matched names

train_match1 <- chem_wiki[`Substance Name` %in% train_commodities]

train_match2 <- atsdr_tsca_ld50_a[`Registry Name` %in% train_commodities]

train_matchs1 <- train_match1$"Substance Name"

train_matchs2 <- train_match2$"Registry Name"

train_match <- unique(c(train_matchs1, train_matchs2))

pander::pander(train_match)


train_match_cas1 <- train_match1$CAS

train_match_cas2 <- train_match2$CAS

train_match_cas <- unique(c(train_match_cas1, train_match_cas2))

pander::pander(train_match_cas)


# remove the matched names

train_commodities2 <- train_commodities[-which(train_commodities %in% train_match)]


# these are the chemical substances without an exact match

pander::pander(train_commodities2)

```

\bigskip
\bigskip
\bigskip
\bigskip

# EcoC^2^S Links

EcoC^2^S Home --- <https://www.ecoccs.com>  
About EcoC^2^S --- <https://www.ecoccs.com/about-ecoc2s.html>  
Services --- <https://www.ecoccs.com/services.html>  
EcoC²S / QUP Shop --- <https://www.ecoccs.com/shopeq/>  
Media --- <https://www.ecoccs.com/media.html>  
Book Search --- <https://www.ecoccs.com/book-search.html>  
R Trainings and Resources provided by EcoC^2^S (Irucka Embry, EIT) --- <https://www.ecoccs.com/rtraining.html> 

\bigskip
\bigskip

# Donations accepted with Liberapay

If you would like to contribute to the continued development of [Irucka Embry&#8217;s R packages](https://www.ecoccs.com/rtraining.html#repos) and/or [Irucka Embry&#8217;s R Examples](https://www.ecoccs.com/rtraining.html#examp), please feel free to donate via the link below:  

[https://liberapay.com/iaembry/donate](https://liberapay.com/iaembry/donate)  

Please feel free to review [Irucka Embry (iaembry)&#8217;s profile](https://liberapay.com/iaembry/) on [Liberapay](https://liberapay.com).  

\bigskip
\bigskip

# Copyright and License

All R code written by Irucka Embry is distributed under the GPL-3 (or later) license, see the [GNU General Public License {GPL} page](https://www.gnu.org/licenses/gpl-3.0.html).  

All written content originally created by Irucka Embry is copyrighted under the Creative Commons Attribution-ShareAlike 4.0 International license. All other written content retains the copyright of the original author(s).  

This work is licensed under a [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/).  
