R/is.MSstats_gcr.R

#' @title Function to check if an object was generated by MSstats::groupComparison() function.
#' @description MSstats::groupComparison() does not return propper S3 or S4 objects. This function can be used to verifiy if an object was generated by groupComparision().
#' @details This function checks for the expected object structure as described for MStats version 3.7.3. The expected column names for the ComparisonResults component are exported to the environment variable exp.names.
#' @param x any R object
#'
#' @return is.MSstats_gcr returns TRUE if its argument was most likely generated by groupComparison()
#' and FALSE otherwise.
#' @export
#'
#' @examples is.MSstats_gcr(sample.data)
#' @seealso \code{\link[MSstats]{groupComparison}}
#'
is.MSstats_gcr <- function(x) {
  #exp.names <- c("Protein", "Label", "log2FC", "SE", "Tvalue", "DF", "pvalue", "adj.pvalue", "issue", "MissingPercentage", "ImputationPercentage")
  if (class(x) != "list") {
    message(paste(x, "is not an instance of class list."))
    return(FALSE)
  } else {
    if ("ComparisonResult" %in% names(x)) {
      if (class(x$ComparisonResult) == "data.frame" && colnames(x$ComparisonResult) == exp.names) {
        return(TRUE)
      } else {
        message("ComparisionResult is not an instance of class data.frame or does not contain expected variables")
        return(FALSE)
      }
    } else {
      message(paste("ComparisionResults not found in", x))
      return(FALSE)
    }
  }
}
tobiasko/posprot documentation built on May 26, 2019, 5:33 a.m.