R/combXPT.R

Defines functions combXPT

Documented in combXPT

combXPT = function(folders, domain)
{
  nFolder = length(folders)
  if (length(nFolder) == 0) stop("You did not specify any folder!")
  if (length(domain) != 1) stop("One domain name needs.")
  folders = Trim(folders)
  domain = UT(domain)

  for (i in 1:nFolder) {
    cFolder = folders[i]
    if (!(substr(cFolder, nchar(cFolder), nchar(cFolder)) %in% c("/", "\\"))) folders[i] = paste0(cFolder, "/")
  }

#  require(foreign)
  for (i in 1:nFolder) {
    cFileName = paste0(folders[i], domain, ".XPT")
    if (file.exists(cFileName)) {
      cXPT = foreign::read.xport(cFileName)
      for (j in 1:ncol(cXPT)) {
        cXPT[,j] = as.character(cXPT[,j])
        cXPT[is.na(cXPT[,j]),j] = ""
      }
      if (i == 1) {
        colNames = colnames(cXPT)
        XPT = cXPT
      } else {
        if (!setequal(colNames, colnames(cXPT))) warning(paste0(folders[i],domain," does not have the same column!"))
        colNames = intersect(colNames, colnames(cXPT))
        XPT = rbind(XPT[colNames], cXPT[colNames])
      }
    }
  }
  return(XPT)
}

Try the pkr package in your browser

Any scripts or data that you put into this service are public.

pkr documentation built on June 11, 2022, 9:05 a.m.