R/dbImporter.R

Defines functions dbImporter

Documented in dbImporter

#' Title
#' Import metabolomics database which saved in xlsx file and screen the database by ion mode and CE voltage.
#'
#' @param dbFile, the xlsx file of metabolomics database with a changeless format.
#' @param ionMode, screen the database by ion mode (P or N, others are not available)
#' @param CE, screen the database by CE voltage (15, 30, 45 and 'all' are available)
#'
#' @return dbData
#' @export dbImporter
#' @importFrom openxlsx read.xlsx
#'
#' @examples
#' dbData <- dbImporter(
#'           dbFile=system.file("extdata/database", "example_database.xlsx", package = "MetEx"),
#'           ionMode='P',
#'           CE="all")
dbImporter <- function(dbFile,
                       ionMode,
                       CE = 'all'){
  # require("openxlsx")

  dbData <- openxlsx::read.xlsx(dbFile,sheet = 1)
  packageStartupMessage("Readind metabolomics database is finished")
  if (ionMode != 'P' & ionMode != 'N'){
    stop("ionMode should be 'P' or 'N', others are not available")
  }
  if (CE != 15 & CE != 30 & CE != 45 & CE != 'all'){
    stop("CE should be 15, 30, 45 or 'all', others are not available")
  }
  dbDataIonMode <- dbData[which(dbData$ionMode== ionMode), ]
  if (CE == 'all'){
    dbDataIonModeCE <- dbDataIonMode
  }
  else {
    dbDataIonModeCE <- dbDataIonMode[which(dbDataIonMode$CE== CE), ]
  }
  packageStartupMessage("Screening metabolomcis database is finished")
  return(dbDataIonModeCE)

}
zhengfj1994/MeTEA documentation built on June 29, 2021, 5:21 a.m.