R/apply.R

#'@title a lapply that unlists!
#'@description run a function over a list or vector, as lapply does,
#'but unlist the results before returning them - a common operation.
#'
#'@param x a vector or list.
#'
#'@param fun the function to apply.
#'
#'@param unname whether or not to also unname the result. Set to
#'TRUE by default.
#'
#'@param ... further arguments to pass to \code{fun}
#'
#'@export
unlapply <- function(x, fun, unname = TRUE, ...){
  result <- unlist(lapply(x,fun,...))
  if(unname){
    return(unname(result))
  }
  return(result)
}
Ironholds/olivr documentation built on May 7, 2019, 6:40 a.m.