aberHRML/classyfireR

table friendly version?

Closed this issue · 2 comments

Hi. This is awesome and just what I need.

You could consider adding a function that makes it easier to add the info to a table though.

Right now I did:

entity_classification_p <- possibly(entity_classification, NA)
entity_classification_classes <- function(InChIKey){
    data <- entity_classification_p(InChIKey)
    
    if((length(class_data) %in% 0:1) && (is.null(class_data) || is.na(class_data))){
        out <- tibble(Kingdom    = NA,
                      Superclass = NA,
                      Class      = NA,
                      Subclass   = NA
        )
    }else{
        out <- tibble(Kingdom    = data$ClassyFire %>% filter(Level == "Kingdom") %>%    pull("Classification"),
                      Superclass = data$ClassyFire %>% filter(Level == "Superclass") %>% pull("Classification"),
                      Class      = data$ClassyFire %>% filter(Level == "Class") %>%      pull("Classification"),
                      Subclass   = data$ClassyFire %>% filter(Level == "Subclass") %>%   pull("Classification")
        )
    }
    
    return(out)
}
data <- data$InChIKey %>%
            map_dfr(entity_classification_classes) %>%
            bind_cols(data)

excellent idea. very happy to make everything fit better with the "tidy" aspects of R. i'll add a devel branch if you want to PR any changes into it

OK. I can add something later. But this could probably be simplified if #1 is resolved.