aberHRML / classyfireR

R Interface to the ClassyFire REST API
https://aberhrml.github.io/classyfireR
10 stars 9 forks source link

table friendly version? #4

Closed stanstrup closed 6 years ago

stanstrup commented 6 years ago

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)
wilsontom commented 6 years ago

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

stanstrup commented 6 years ago

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