Skip to content

Instantly share code, notes, and snippets.

@stanstrup
Created August 17, 2019 18:38
Show Gist options
  • Save stanstrup/7b53b2238a4dda0156c6587bf67f4822 to your computer and use it in GitHub Desktop.
Save stanstrup/7b53b2238a4dda0156c6587bf67f4822 to your computer and use it in GitHub Desktop.
cs_prop_tab <- function(csid){
require(dplyr)
require(webchem)
require(rcdk)
cs_prop <- cs_prop(csid, verbose=TRUE)
if(is.na(cs_prop)){
return(bind_cols(cs_acd_tab = tibble(),
cs_epi_pred_tab = tibble(),
cs_epi_exp_tab = tibble()
)
)
}
cs_acd_tab <- cs_prop[[1]]$acd %>%
as.tbl %>%
mutate(variable = paste0("acd_",variable)) %>%
select(variable, value) %>%
spread(variable, value)
if(nrow(cs_prop[[1]]$epi)==0){
cs_epi_pred_tab <- tibble()
cs_epi_exp_tab <- tibble()
}else{
cs_epi_pred_tab <- cs_prop[[1]]$epi %>%
as.tbl %>%
mutate(prop = paste0("epi_pred_",prop)) %>%
select(prop, value_pred) %>%
spread(prop, value_pred)
cs_epi_exp_tab <- cs_prop[[1]]$epi %>%
as.tbl %>%
mutate(prop = paste0("epi_exp_",prop)) %>%
select(prop, value_exp) %>%
spread(prop, value_exp)
}
return(bind_cols(cs_acd_tab, cs_epi_pred_tab, cs_epi_exp_tab))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment