Skip to content

Commit

Permalink
Merge pull request #288 from ldecicco-USGS/master
Browse files Browse the repository at this point in the history
Slimming namespace
  • Loading branch information
ldecicco-USGS authored Aug 1, 2018
2 parents d67d9fc + 5308957 commit d94e632
Show file tree
Hide file tree
Showing 92 changed files with 931 additions and 573 deletions.
9 changes: 4 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: toxEval
Type: Package
Title: ToxCast Evaluations
Version: 1.0.0
Date: 2018-07-11
Date: 2018-07-31
Authors@R: c(person("Laura", "DeCicco",
role = c("aut","cre"),
email = "[email protected]"),
Expand Down Expand Up @@ -30,9 +30,9 @@ Imports:
DT (>= 0.1.24),
leaflet (>= 1.0.0),
ggplot2 (>= 3.0.0),
magrittr,
shiny,
shinydashboard,
data.table,
RColorBrewer,
readxl,
tools,
Expand All @@ -41,11 +41,10 @@ Imports:
Suggests:
rmarkdown,
testthat,
knitr,
htmltools
knitr
BugReports: https://github.com/USGS-R/toxEval/issues
VignetteBuilder: knitr
BuildVignettes: true
LazyLoad: yes
LazyData: yes
RoxygenNote: 6.0.1
RoxygenNote: 6.1.0
38 changes: 1 addition & 37 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -28,45 +28,9 @@ export(rank_sites_DT)
export(remove_flags)
export(tox_boxplot_data)
export(tox_chemicals)
import(DT)
import(RColorBrewer)
import(data.table)
import(ggplot2)
import(leaflet)
import(shinyAce)
import(shinydashboard)
importFrom(dplyr,anti_join)
importFrom(dplyr,arrange)
importFrom(dplyr,desc)
importFrom(dplyr,distinct)
importFrom(dplyr,filter)
importFrom(dplyr,filter_)
importFrom(dplyr,full_join)
importFrom(dplyr,group_by)
importFrom(dplyr,group_by_)
importFrom(dplyr,left_join)
importFrom(dplyr,mutate)
importFrom(dplyr,mutate_)
importFrom(dplyr,rename)
importFrom(dplyr,rename_)
importFrom(dplyr,right_join)
importFrom(dplyr,select)
importFrom(dplyr,select_)
importFrom(dplyr,summarise)
importFrom(dplyr,summarize)
importFrom(grDevices,colorRampPalette)
importFrom(leaflet,addCircles)
importFrom(leaflet,addLegend)
importFrom(leaflet,clearControls)
importFrom(leaflet,clearShapes)
importFrom(leaflet,leaflet)
importFrom(shiny,runApp)
importFrom(shinycssloaders,withSpinner)
importFrom(magrittr,"%>%")
importFrom(stats,median)
importFrom(stats,quantile)
importFrom(tidyr,gather)
importFrom(tidyr,spread)
importFrom(tidyr,unite)
importFrom(tools,file_ext)
importFrom(tools,toTitleCase)
importFrom(utils,packageVersion)
1 change: 0 additions & 1 deletion R/clean_endPoint_info.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#' filtered out and some additional categories in intended_target_family and
#' intended_target_family_sub. The names in intended_target_family
#' are revised to look more appealing in graphs and tables.
#' @importFrom tools toTitleCase
#' @examples
#' end_point_info <- end_point_info
#' cleaned_ep <- clean_endPoint_info(end_point_info)
Expand Down
1 change: 1 addition & 0 deletions R/create_toxEval.R
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ rm_em_dash <- function(df){
#' @param \dots additional parameters
#'
#' @export
#' @importFrom magrittr "%>%"
#' @examples
#' path_to_tox <- system.file("extdata", package="toxEval")
#' file_name <- "OWC_data_fromSup.xlsx"
Expand Down
75 changes: 36 additions & 39 deletions R/endpoint_hits.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@
#' @export
#' @return data frame with one row per endpoint that had a hit (based on the
#' hit_threshold). The columns are based on the category.
#' @import DT
#' @rdname endpoint_hits_DT
#' @importFrom stats median
#' @importFrom tidyr spread unite
#' @importFrom dplyr full_join filter mutate select left_join right_join
#' @examples
#' # This is the example workflow:
#' path_to_tox <- system.file("extdata", package="toxEval")
Expand Down Expand Up @@ -72,8 +69,8 @@ endpoint_hits_DT <- function(chemical_summary,
if(category == "Chemical"){
orig_names <- names(fullData)

casKey <- select(chemical_summary, chnm, CAS) %>%
distinct()
casKey <- dplyr::select(chemical_summary, chnm, CAS) %>%
dplyr::distinct()

numeric_hits <- fullData
hits <- sapply(fullData, function(x) as.character(x))
Expand All @@ -100,14 +97,14 @@ endpoint_hits_DT <- function(chemical_summary,
n <- ncol(fullData)-1

if(n > 20 & n<30){
colors <- c(brewer.pal(n = 12, name = "Set3"),
brewer.pal(n = 8, name = "Set2"),
brewer.pal(n = max(c(3,n-20)), name = "Set1"))
colors <- c(RColorBrewer::brewer.pal(n = 12, name = "Set3"),
RColorBrewer::brewer.pal(n = 8, name = "Set2"),
RColorBrewer::brewer.pal(n = max(c(3,n-20)), name = "Set1"))
} else if (n <= 20){
colors <- c(brewer.pal(n = 12, name = "Set3"),
brewer.pal(n = max(c(3,n-12)), name = "Set2"))
colors <- c(RColorBrewer::brewer.pal(n = 12, name = "Set3"),
RColorBrewer::brewer.pal(n = max(c(3,n-12)), name = "Set2"))
} else {
colors <- colorRampPalette(brewer.pal(11,"Spectral"))(n)
colors <- colorRampPalette(RColorBrewer::brewer.pal(11,"Spectral"))(n)
}

fullData_dt <- DT::datatable(fullData, extensions = 'Buttons',
Expand All @@ -119,13 +116,13 @@ endpoint_hits_DT <- function(chemical_summary,
order=list(list(1,'desc'))))

for(i in 2:ncol(fullData)){
fullData_dt <- formatStyle(fullData_dt,
fullData_dt <- DT::formatStyle(fullData_dt,
names(fullData)[i],
backgroundColor = colors[i])

if(category != "Chemical"){
fullData_dt <- formatStyle(fullData_dt, names(fullData)[i],
background = styleColorBar(range(fullData[,names(fullData)[i]],na.rm = TRUE), 'goldenrod'),
fullData_dt <- DT::formatStyle(fullData_dt, names(fullData)[i],
background = DT::styleColorBar(range(fullData[,names(fullData)[i]],na.rm = TRUE), 'goldenrod'),
backgroundSize = '100% 90%',
backgroundRepeat = 'no-repeat',
backgroundPosition = 'center' )
Expand All @@ -152,48 +149,48 @@ endpoint_hits <- function(chemical_summary,
fullData <- fullData_init

if(category == "Chemical"){
chemical_summary <- mutate(chemical_summary, category = chnm)
chemical_summary <- dplyr::mutate(chemical_summary, category = chnm)
} else if (category == "Chemical Class"){
chemical_summary <- mutate(chemical_summary, category = Class)
chemical_summary <- dplyr::mutate(chemical_summary, category = Class)
} else {
chemical_summary <- mutate(chemical_summary, category = Bio_category)
chemical_summary <- dplyr::mutate(chemical_summary, category = Bio_category)
}

if(length(unique(chemical_summary$site)) > 1){

if(!sum_logic){
fullData <- chemical_summary %>%
group_by(site, category, endPoint, date) %>%
summarize(sumEAR = max(EAR)) %>%
group_by(site, category, endPoint) %>%
summarize(meanEAR = ifelse(mean_logic, mean(sumEAR),max(sumEAR))) %>%
group_by(category, endPoint) %>%
summarize(nSites = sum(meanEAR > hit_threshold)) %>%
spread(category, nSites)
dplyr::group_by(site, category, endPoint, date) %>%
dplyr::summarize(sumEAR = max(EAR)) %>%
dplyr::group_by(site, category, endPoint) %>%
dplyr::summarize(meanEAR = ifelse(mean_logic, mean(sumEAR),max(sumEAR))) %>%
dplyr::group_by(category, endPoint) %>%
dplyr::summarize(nSites = sum(meanEAR > hit_threshold)) %>%
tidyr::spread(category, nSites)
} else {
fullData <- chemical_summary %>%
group_by(site, category, endPoint, date) %>%
summarize(sumEAR = sum(EAR)) %>%
group_by(site, category, endPoint) %>%
summarize(meanEAR = ifelse(mean_logic, mean(sumEAR),max(sumEAR))) %>%
group_by(category, endPoint) %>%
summarize(nSites = sum(meanEAR > hit_threshold)) %>%
spread(category, nSites)
dplyr::group_by(site, category, endPoint, date) %>%
dplyr::summarize(sumEAR = sum(EAR)) %>%
dplyr::group_by(site, category, endPoint) %>%
dplyr::summarize(meanEAR = ifelse(mean_logic, mean(sumEAR),max(sumEAR))) %>%
dplyr::group_by(category, endPoint) %>%
dplyr::summarize(nSites = sum(meanEAR > hit_threshold)) %>%
tidyr::spread(category, nSites)
}

} else {
if(!sum_logic){
fullData <- chemical_summary %>%
group_by(category, endPoint) %>%
summarise(nSites = sum(EAR > hit_threshold)) %>%
spread(category, nSites)
dplyr::group_by(category, endPoint) %>%
dplyr::summarise(nSites = sum(EAR > hit_threshold)) %>%
tidyr::spread(category, nSites)
} else {
fullData <- chemical_summary %>%
group_by(category, endPoint, date) %>%
summarize(sumEAR = sum(EAR)) %>%
group_by(category, endPoint) %>%
summarise(nSites = sum(sumEAR > hit_threshold)) %>%
spread(category, nSites)
dplyr::group_by(category, endPoint, date) %>%
dplyr::summarize(sumEAR = sum(EAR)) %>%
dplyr::group_by(category, endPoint) %>%
dplyr::summarise(nSites = sum(sumEAR > hit_threshold)) %>%
tidyr::spread(category, nSites)
}
}

Expand Down
14 changes: 1 addition & 13 deletions R/explore_endpoints.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,12 @@
#'
#' @param browse Logical. Use browser for running Shiny app.
#' @export
#' @importFrom shiny runApp
#' @importFrom tools file_ext
#' @importFrom leaflet leaflet
#' @importFrom leaflet addLegend
#' @importFrom leaflet addCircles
#' @importFrom leaflet clearControls
#' @importFrom leaflet clearShapes
#' @importFrom shinycssloaders withSpinner
#' @import DT
#' @import ggplot2
#' @import data.table
#' @import RColorBrewer
#' @import shinydashboard
#' @import shinyAce
#' @examples
#' \dontrun{
#' explore_endpoints()
#' }
explore_endpoints <- function(browse=TRUE){
runApp(system.file('shiny', package='toxEval'), launch.browser = browse)
shiny::runApp(system.file('shiny', package='toxEval'), launch.browser = browse)
}
3 changes: 1 addition & 2 deletions R/filter_endPoint_info.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#' "BSK" (BioSeek) assay is removed.
#' @param remove_groups Vector of groups within the selected 'groupCol' to remove.
#' @export
#' @importFrom dplyr rename
#' @examples
#' end_point_info <- end_point_info
#' cleaned_ep <- clean_endPoint_info(end_point_info)
Expand All @@ -43,7 +42,7 @@ filter_groups <- function(ep,
assay_source_name <- assay_component_endpoint_name <- ".dplyr"

ep <- ep[,c("assay_component_endpoint_name",groupCol,"assay_source_name")] %>%
rename(endPoint = assay_component_endpoint_name,
dplyr::rename(endPoint = assay_component_endpoint_name,
assaysFull = assay_source_name)
names(ep)[names(ep) == groupCol] <- "groupCol"

Expand Down
20 changes: 9 additions & 11 deletions R/get_ACC.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#' @param CAS Vector of CAS.
#' @return data frame with columns CAS, chnm, flags, endPoint, ACC, MlWt, and ACC_value
#' @export
#' @importFrom tidyr gather
#' @importFrom dplyr select filter right_join mutate
#' @examples
#' CAS <- c("121-00-6","136-85-6","80-05-7","84-65-1","5436-43-1","126-73-8")
#' ACC <- get_ACC(CAS)
Expand All @@ -22,19 +20,19 @@ get_ACC <- function(CAS){
# Getting rid of NSE warnings:
Structure_MolWt <- Substance_CASRN <- casn <- chnm <- flags <- MlWt <- ACC_value <- casrn <- endPoint <- ".dplyr"

chem_list <- select(tox_chemicals,
casrn = Substance_CASRN,
MlWt = Structure_MolWt) %>%
filter(casrn %in% CAS)
chem_list <- dplyr::select(tox_chemicals,
casrn = Substance_CASRN,
MlWt = Structure_MolWt) %>%
dplyr::filter(casrn %in% CAS)

ACC <- ToxCast_ACC %>%
filter(CAS %in% CAS) %>%
right_join(chem_list,
dplyr::filter(CAS %in% CAS) %>%
dplyr::right_join(chem_list,
by= c("CAS"="casrn")) %>%
data.frame() %>%
mutate(ACC_value = 10^ACC) %>%
mutate(ACC_value = ACC_value * MlWt) %>%
filter(!is.na(ACC_value))
dplyr::mutate(ACC_value = 10^ACC,
ACC_value = ACC_value * MlWt) %>%
dplyr::filter(!is.na(ACC_value))

if(any(is.na(ACC$MlWt))){
warning("Some chemicals are missing molecular weights")
Expand Down
Loading

0 comments on commit d94e632

Please sign in to comment.