R/m067.phen.R

Defines functions m067.phen

#----------------------
# Get phenotype data
#----------------------

#' @export
m067.phen <- function(dir,
                      arg)
{

  #t_sample = c('supernatant', 'rna'),

  ### require packages
  m067.required_packages()

  ### argument Group
  # group <- match.arg(group)

  ### argument dir
  if(missing(dir)){
    dir <- m067.phendir()
  }
  stopifnot(file.exists(dir))

  ### argument filter
  #if(!missing(filter)){
  #  stopifnot(class(filter) == 'character')
  #}

  # list of files
  dat_file <- list.files(dir, pattern = '.csv', full.names = TRUE)

  # read data in 'dat_file'
	options(datatable.fread.dec.locale = 'es_ES.UTF-8')	## alert to ```locale``` config!!

  ### read data in 'dat.file'
  dat_imp <- lapply(dat_file, fread, sep = ';', dec = '.')

    # update list of data in 'm067.phen.update_id.R' file
    dat_imp <- m067.update.dat_01(dat_imp) # dat_imp[[1]] original 'pid' & 't_point'
	  dat_imp <- m067.update.dat_02(dat_imp) # dat_imp[[2]] add 'sid', 'nida' from bagamoyo
    dat_imp <- m067.update.dat_03(dat_imp) # dat_imp[[5]] add 'sid', 'nida' from manhiça
    dat_imp <- m067.update.dat_04(dat_imp) # dat_imp[[8]] add 'sid', 'brady' from lambarene

    # update 'M21' & 'M32' of data in 'm067.phen.update_spnt.R' file
    dat_imp <- m067.update.dat_02_m21(dat_imp) # dat_imp[[3]] spnt 'M23' from bagamoyo
    dat_imp <- m067.update.dat_02_m32(dat_imp) # dat_imp[[4]] spnt 'M32' from bagamoyo
    dat_imp <- m067.update.dat_03_m21(dat_imp) # dat_imp[[6]] spnt 'M21' from manhiça
    dat_imp <- m067.update.dat_03_m32(dat_imp) # dat_imp[[7]] spnt 'M32' from manhiça
    dat_imp <- m067.update.dat_04_m21_m32(dat_imp) # dat_imp[[9]] spnt 'M23' & 'M32' from lambarene

      # rbind all 'sites' & 't_point'
      dat_m21_m32 <- rbind(dat_imp[[3]], dat_imp[[4]],
        dat_imp[[6]], dat_imp[[7]],
        dat_imp[[9]])

      # update 'dat_m21_m32'
      dat_m21_m32 <- m067.update.dat_m21_m32(dat_m21_m32)

      # data.frame 'as_tibble'
      dat <- dat_m21_m32 %>%
        as_tibble()

  ### return
  return(dat_m21_m32)
}
mvazquezs/m067tools documentation built on April 24, 2019, 6:52 p.m.