Skip to content

Commit

Permalink
Merge pull request #204 from ldecicco-USGS/master
Browse files Browse the repository at this point in the history
Splitting up big function
  • Loading branch information
ldecicco-USGS authored Oct 31, 2017
2 parents c9266b6 + 631cce9 commit 9600acd
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 14 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: ToxCast Evaluations
Version: 0.3.8.9003
Version: 0.3.8.9004
Date: 2017-10-04
Authors@R: c( person("Steven", "Corsi", role = c("aut"),
email = "srcorsi@usgs.gov"),
Expand Down
51 changes: 38 additions & 13 deletions R/get_chemical_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,30 +73,55 @@ get_chemical_summary <- function(ACClong, filtered_ep,

graphData <- graph_chem_data(chemicalSummary)

orderClass <- graphData %>%
orderClass_df <- orderClass(graphData)

orderChem_df <- orderChem(graphData, orderClass_df)

chemicalSummary$chnm <- factor(chemicalSummary$chnm,
levels = orderChem_df$chnm)

chemicalSummary$Class <- factor(chemicalSummary$Class,
levels = rev(levels(orderChem_df$Class)))

return(chemicalSummary)
}

#' orderClass
#'
#' @param graphData data frame
orderClass <- function(graphData){

chnm <- Class <- maxEAR <- median <- max_med <- ".dplyr"

orderClass_df <- graphData %>%
group_by(chnm, Class) %>%
summarise(median = quantile(maxEAR[maxEAR != 0],0.5)) %>%
group_by(Class) %>%
summarise(max_med = max(median, na.rm = TRUE)) %>%
arrange(desc(max_med))

orderChem <- graphData %>%

return(orderClass_df)
}

#' orderChem
#'
#' @param graphData data frame
#' @param orderClass_df data frame
orderChem <- function(graphData, orderClass_df){

chnm <- Class <- maxEAR <- median <- ".dplyr"

orderChem_df <- graphData %>%
group_by(chnm,Class) %>%
summarise(median = quantile(maxEAR[maxEAR != 0],0.5)) %>%
data.frame() %>%
mutate(Class = factor(Class, levels = rev(as.character(orderClass$Class))))

orderChem$median[is.na(orderChem$median)] <- 0
mutate(Class = factor(Class, levels = rev(as.character(orderClass_df$Class))))

orderChem <- arrange(orderChem, Class, median)

chemicalSummary$chnm <- factor(chemicalSummary$chnm,
levels = orderChem$chnm)
orderChem_df$median[is.na(orderChem_df$median)] <- 0

chemicalSummary$Class <- factor(chemicalSummary$Class,
levels = rev(levels(orderChem$Class)))
orderChem_df <- arrange(orderChem_df, Class, median)

return(chemicalSummary)
return(orderChem_df)
}

#' remove_flags
Expand Down
16 changes: 16 additions & 0 deletions man/orderChem.Rd

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

14 changes: 14 additions & 0 deletions man/orderClass.Rd

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

0 comments on commit 9600acd

Please sign in to comment.