R/get-fields.R

Defines functions get.fields.extraInfo get.fields.data get.fields.treedata

##' @rdname get.fields-methods
##' @aliases get.fields,treedata
##' @exportMethod get.fields
setMethod("get.fields", signature(object = "treedata"),
          function(object) {
              get.fields.treedata(object)
          })


get.fields.treedata <- function(object) {
    fields1 <- get.fields.data(object)
    fields2 <- get.fields.extraInfo(object)
    return(c(fields1, fields2))
}

get.fields.data <- function(object){
    if (nrow(object@data) > 0) {
        fields <- colnames(object@data)
        fields <- fields[fields != "node"]
    } else {
        fields <- ""
    }
    return(fields)
}

get.fields.extraInfo <- function(object){
    extraInfo <- object@extraInfo
    if (nrow(extraInfo) > 0) {
        cn <- colnames(extraInfo)
        i <- match(c("x", "y", "isTip", "node", "parent", "label", "branch", "branch.length"), cn)
        i <- i[!is.na(i)]
        fields <- cn[-i]
        return(fields)
    }else{
        return(character(0))
    }
}

Try the tidytree package in your browser

Any scripts or data that you put into this service are public.

tidytree documentation built on Aug. 10, 2023, 5:07 p.m.