R/loadTargetFile.R

Defines functions loadTargetFile

Documented in loadTargetFile

#' Load file containing sample info
#'
#' Load file containing sample info
#'
#' @param targetFile path to the target file
#' @param varInt variable(s) on which sorting the target
#' @param condRef reference condition(s) of \code{varInt}
#' @return A \code{data.frame} containing the informations about the samples (name, file and group)
#' @author Marie-Agnes Dillies and Hugo Varet

# created Feb 6th, 2012
# modified Jan 10th, 2013 (sort by group)
# modified Sept 24th, 2013 (sort=TRUE by default)
# modified Oct 25th, 2013 (added varInt argument)
# modified Nov 20th, 2013 (rownames, added condRef arg, deleted sort arg)
# modified Feb 19th, 2014 (added as.factor to coerce varInt to be a factor)
# modified Nov 15th, 2019 (new ordering of the samples)

loadTargetFile <- function(targetFile, varInt, condRef){
  target <- read.table(targetFile, header=TRUE, sep="\t", stringsAsFactors=FALSE)
  for (i in length(varInt):1){
    lev <- c(condRef[i], unique(target[,varInt[i]]))
    target[,varInt[i]] <- factor(target[,varInt[i]], levels=lev[!duplicated(lev)])
    target <- target[order(target[,varInt[i]]),]
  }
  rownames(target) <- as.character(target[,1])
  return(target)
}
biomics-pasteur-fr/RNADiff documentation built on Aug. 27, 2020, 12:44 a.m.