R/ExposomeSet-expos.R

#' @describeIn ExposomeSet Returns a \code{data.frame} with exposures.
setMethod(
    f = "expos",
    signature = "ExposomeSet",
    definition = function(object) {
        ms <- data.frame(t(object@assayData$exp))
        if( !".type" %in% colnames(fData(object))) {
            stop("Invalid 'ExposomeSet'. It has no '.type' column in its 'fData'.")
        }
        type <- fData(object)[colnames(ms), ".type"]
        expo.n <- rownames(fData(object))
        names(type) <- expo.n
        for(ii in expo.n) {
            if(type[ii] == "numeric") {
                ms[ , ii] <- as.numeric( as.character( ms[ , ii]) )
            } else if(type[ii] == "factor") {
                ms[ , ii] <- as.factor(ms[ , ii])
            }
        }
        ms
    }
)

Try the rexposome package in your browser

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

rexposome documentation built on March 13, 2021, 2:01 a.m.