R/aaa_utils.R

Defines functions ensure_names bind_list

ensure_names = function(x, cn) {
  sd = c(setdiff(names(x), cn))
  for (isd in sd) {
    x[[isd]] = NA
  }
  sd = setdiff(cn, names(x))
  for (isd in sd) {
    x[[isd]] = NA
  }
  return(x)
}

bind_list = function(L) {
  L = lapply(L, function(x) {
    if (!is.data.frame(x)) {
      x = unlist(x)
    }
    x
  })
  cn = sapply(L, names)
  cn = unique(c(unlist(cn)))
  L = lapply(L, function(x){
    x = ensure_names(x, cn)
    x[cn]
  })
  L = do.call("rbind", L)
  if (!is.data.frame(L)) {
    L = as.data.frame(L, stringsAsFactors = FALSE)
  }
  return(L)
}

Try the glassdoor package in your browser

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

glassdoor documentation built on May 2, 2019, 11:12 a.m.