blob: aecc87c5e4a90b7ef2decf6186daeb542378279d [file] [log] [blame]
# File src/library/base/R/lapply.R
# Part of the R package, https://www.R-project.org
#
# Copyright (C) 1995-2018 The R Core Team
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# A copy of the GNU General Public License is available at
# https://www.R-project.org/Licenses/
lapply <- function (X, FUN, ...)
{
FUN <- match.fun(FUN)
## internal code handles all vector types, including expressions
## However, it would be OK to have attributes which is.vector
## disallows.
if(!is.vector(X) || is.object(X)) X <- as.list(X)
## Note ... is not passed down. Rather the internal code
## evaluates FUN(X[i], ...) in the frame of this function
.Internal(lapply(X, FUN))
}
rapply <-
function(object, f, classes = "ANY", deflt = NULL,
how = c("unlist", "replace", "list"), ...)
{
## 'object' is checked in C now
how <- match.arg(how)
res <- .Internal(rapply(object, f, classes, deflt, how))
if(how == "unlist") unlist(res, recursive = TRUE) else res
}