---
title: "Chemical Names"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output: 
  rmarkdown::html_vignette:
    toc: true
    number_sections: false
vignette: >
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteIndexEntry{Chemical Names}
  \usepackage[utf8]{inputenc}
---

```{r setup, include=FALSE}
library(toxEval)
library(dplyr)
knitr::opts_chunk$set(echo = TRUE,
                      warning = FALSE,
                      message = FALSE)
```

Up until version 1.3.1, `toxEval` only required "CAS" and "Class" in the Chemicals tab of the data (see `vignette("PrepareData", package = "toxEval")`. In those previous versions of `toxEval`, the chemical names were taken from the `Substance_Name` in the included data frame \code{tox_chemicals}. The information in that table (including substance name) come from the ToxCast database.

Many users are using `toxEval` for user-curated benchmarks workflows, and the auto-generated chemical names became difficult to work with. So going forward from version 1.3.1, the chemical names seen in tables and figures come from the "Chemical" tab.

To get the pre-1.3.1 names, use a join. We'll open the example data, delete the pre-defined column of chemical names, and show how to do a join using `tox_chemicals`.

```{r}
library(toxEval)
library(dplyr)
path_to_tox <- system.file("extdata", package = "toxEval")
file_name <- "OWC_data_fromSup.xlsx"

full_path <- file.path(path_to_tox, file_name)

chem_info <- readxl::read_xlsx(full_path, sheet = "Chemicals")

#remove Chemical column for demonstration:
chem_info <- chem_info[, c("CAS", "Class")]

tox_chemicals <- tox_chemicals

chem_info_with_names <- chem_info %>%
  left_join(select(tox_chemicals,
                   CAS = casn,
                   Chemical = chnm),
            by = "CAS")

head(chem_info_with_names)

```

Users need to supply their own names for chemicals that are not in the `tox_chemicals` data frame. 

