R/tools.r

Defines functions named.list set.names sc first.non.null id.to.index

named.list = function(names, ...) {
	li = list(...)
	names(li) = names
	li
}

set.names = function(x, names) {
	names(x) = names
	x
}

deparse1 = function (call, collapse = "") 
{
    paste0(deparse(call, width = 500), collapse = collapse)
}

#' Like paste0 but returns an empty vector if some string is empty
sc = function(..., sep="", collapse=NULL) {
  str = list(...)
  restore.point("str.combine")
  len = sapply(str,length)
  if (any(len==0))
    return(vector("character",0))
  paste0(...,sep=sep,collapse=collapse)
}


first.non.null = function(...) {
  args = list(...)
  args = args[!sapply(args, is.null)]
  if (length(args)==0) return(NULL)
  args[[1]]
}

# takes a vector of ids
# replaces it by a vector of indices starting from 1
id.to.index = function(id, unique.ids = unique(id)) {
	match(id, unique.ids)
}
skranz/XEconDB documentation built on May 30, 2019, 2:02 a.m.