#' @title Exposures and phenotyphes data
#'
#' @description Extract a table with the exposures and phenotypes data for all the individuals of an
#' Exposome Set
#'
#' @param exposomeSet \code{ExposomeSet} Exposome Set object
#' @param target \code{character} To specify target of output table, \code{all} to include exposures and phenotypes,
#' \code{exposures} to include only the exposures and \code{phenotypes} to include only the phenotypes. Default \code{all}
#' @param exposures_type \code{character} Type of the exposures to be kept, usually
#' \code{"numeric"} or \code{"character"/"factor"}. If \code{NULL} all the exposures will be kept.
#'
#' @return \code{data.frame} With exposures and phenotypes
#' @export
exposures_pData <- function(exposomeSet, target = "all", rownames2col = FALSE, exposures_type = NULL) {
if(target == "all"){
data <- cbind(rexposome::expos(exposomeSet), Biobase::pData(exposomeSet))
}
else if(target == "exposures"){
if(!is.null(exposures_type)){
select <- rownames(Biobase::fData(exposomeSet))[Biobase::fData(exposomeSet)$`.type` == exposures_type]
data <- rexposome::expos(exposomeSet)[ , select]
} else {
data <- rexposome::expos(exposomeSet)
}
}
else if(target == "phenotypes"){
data <- Biobase::pData(exposomeSet)
}
else{stop("Incorrect 'target' argument. Options: 'all', 'exposures' and 'phenotypes'", call.=FALSE)}
if(rownames2col){
data %>% tibble::rownames_to_column("id") -> data
}
return(data)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.