R/load_mat.R

Defines functions getnrow load_mat

Documented in getnrow load_mat

##########################################################################################
# devtools::document() # to update documentation after making changes
# devtools::install() # to install the package in the curren system
# library("myfirstpackage") # to load the package
##########################################################################################

##########################################################################################
#' Load a Matrix
#'
#' This function loads a file as a matrix. It assumes that the first column
#' contains the rownames and the subsequent columns are the sample identifiers.
#' Any rows with duplicated row names will be dropped with the first one being
#' kepted.
#'
#' @param infile Path to the input file
#' @return A matrix of the infile
#' @export
load_mat <- function(infile){
  in.dt <- data.table::fread(infile, header = TRUE)
  in.dt <- in.dt[!duplicated(in.dt[, 1]), ]
  in.mat <- as.matrix(in.dt[, -1, with = FALSE])
  rownames(in.mat) <- unlist(in.dt[, 1, with = FALSE])
  in.mat
}
##########################################################################################


##########################################################################################
#' Load a Matrix
#'
#' This function loads a file and return the number of rows
#'
#' @param infile Path to the input file
#' @returnnumber of rows
#' @export
getnrow <- function(infile){
  in.dt <- data.table::fread(infile, header = TRUE)
  numberRow=nrow(in.dt)
  numberRow
}
##########################################################################################
jianvhuang/testing documentation built on May 14, 2020, 12:34 a.m.