Skip to content

Commit

Permalink
Initial work for making "Chemical" a mandatory column in the chemical…
Browse files Browse the repository at this point in the history
… tab.
  • Loading branch information
ldecicco-USGS committed Jun 2, 2023
1 parent 27eb744 commit b1faa66
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 57 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: toxEval
Type: Package
Title: Exploring Biological Relevance of Environmental Chemistry Observations
Version: 1.3.0
Version: 1.3.1
Authors@R: c(person("Laura", "DeCicco",
role = c("aut","cre"),
email = "ldecicco@usgs.gov",
Expand Down
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
toxEval 1.3.1
===========
* Made "Chemical" a required column in the Chemical tab. Now all plot names will key off that column instead of the names listed in tox_chemicals.
*

toxEval 1.3.0
===========
* Switched to version 3.5 of the ToxCast database
Expand Down
4 changes: 2 additions & 2 deletions R/create_toxEval.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ create_toxEval <- function(excel_file_path, ...) {
names(chem_info) <- names(chem_info) %>%
allowed_names(c("casrn", "casn", "CASRN", "CASN"), "CAS")

if ("CAS" %in% names(chem_info)) {
if (all(c("CAS", "Chemical") %in% names(chem_info))){
chem_info$CAS <- as.character(chem_info$CAS)
} else {
message("Chemical tab missing CAS column")
message("Chemical tab missing CAS or Chemical column")
}
}

Expand Down
31 changes: 15 additions & 16 deletions R/get_chemical_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,30 +83,29 @@ get_chemical_summary <- function(tox_list, ACC = NULL, filtered_ep = "All",

if (is.null(ACC)) {
ACC <- tox_list[["benchmarks"]]
ACC <- dplyr::select(ACC, CAS, endPoint, ACC_value, groupCol)
} else {
ACC <- dplyr::select(ACC, CAS, chnm, endPoint, ACC_value)
ACC <- dplyr::select(ACC, CAS, endPoint, ACC_value)
}




if (is.character(chem_data$Value)) {
chem_data$Value <- as.numeric(chem_data$Value)
}

chemical_summary <- full_join(ACC,
dplyr::select(
chem_data,
CAS, SiteID, Value, `Sample Date`
),
by = "CAS"
) %>%
filter(
dplyr::select(chem_data,
CAS, SiteID, Value, `Sample Date`),
by = "CAS") %>%
dplyr::filter(
!is.na(ACC_value),
!is.na(Value)
) %>%
mutate(EAR = Value / ACC_value) %>%
rename(
site = SiteID,
date = `Sample Date`
)
!is.na(Value)) %>%
dplyr::mutate(EAR = Value / ACC_value) %>%
dplyr::rename(site = SiteID,
date = `Sample Date`) %>%
dplyr::left_join(dplyr::select(chem_info, CAS, chnm = Chemical),
by = "CAS")

if (all(filtered_ep != "All")) {
chemical_summary <- chemical_summary %>%
Expand Down
43 changes: 6 additions & 37 deletions R/side_by_side.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ get_concentration_summary <- function(tox_list,
chem_data = NULL,
chem_site = NULL,
chem_info = NULL,
tox_names = TRUE) {
tox_names = FALSE) {
# Getting rid of NSE warnings:
chnm <- endPoint <- ACC_value <- Substance_Name <- Value <- `Sample Date` <- SiteID <- ".dplyr"
EAR <- `Short Name` <- Substance_CASRN <- CAS <- Chemical <- Class <- site <- casrn <- groupCol <- ".dplyr"
Expand Down Expand Up @@ -189,42 +189,11 @@ get_concentration_summary <- function(tox_list,
endPoint = "Concentration"
) %>%
left_join(select(chem_site,
site = SiteID,
shortName = `Short Name`
),
by = "site"
) %>%
left_join(select(chem_info, CAS, Class), by = "CAS")

if (tox_names) {
tox_names_key <- tox_chemicals %>%
select(CAS = Substance_CASRN, chnm = Substance_Name) %>%
filter(CAS %in% chem_info$CAS)

chemical_summary <- chemical_summary %>%
left_join(tox_names_key, by = "CAS")

if (any(is.na(chemical_summary$chnm))) {
if ("Chemical" %in% names(chem_info)) {
chemical_summary <- chemical_summary %>%
left_join(select(chem_info, CAS, Chemical), by = "CAS")
} else {
chemical_summary$Chemical <- as.character(as.numeric(factor(chemical_summary$CAS)))
}

chemical_summary$chnm[is.na(chemical_summary$chnm)] <- chemical_summary$Chemical[is.na(chemical_summary$chnm)]

chemical_summary <- select(chemical_summary, -Chemical)
}
} else {
if ("Chemical" %in% names(chem_info)) {
chemical_summary <- chemical_summary %>%
left_join(select(chem_info, CAS, chnm = Chemical), by = "CAS")
} else {
message("Add a Chemical column to the Chemicals tab to get custom chemical names")
chemical_summary$chnm <- as.character(as.numeric(factor(chemical_summary$CAS)))
}
}
site = SiteID,
shortName = `Short Name`),
by = "site") %>%
left_join(select(chem_info, CAS, Class, chnm = Chemical),
by = "CAS")

graphData <- graph_chem_data(chemical_summary)

Expand Down
2 changes: 1 addition & 1 deletion man/get_concentration_summary.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b1faa66

Please sign in to comment.