-
Notifications
You must be signed in to change notification settings - Fork 292
Expand file tree
/
Copy pathas_mapper.Rd
More file actions
59 lines (47 loc) · 1.88 KB
/
as_mapper.Rd
File metadata and controls
59 lines (47 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/map-mapper.R
\name{as_mapper}
\alias{as_mapper}
\alias{as_mapper.character}
\alias{as_mapper.numeric}
\alias{as_mapper.list}
\title{Convert an object into a mapper function}
\usage{
as_mapper(.f, ...)
\method{as_mapper}{character}(.f, ..., .null, .default = NULL)
\method{as_mapper}{numeric}(.f, ..., .null, .default = NULL)
\method{as_mapper}{list}(.f, ..., .null, .default = NULL)
}
\arguments{
\item{.f}{A function, formula, or vector (not necessarily atomic).
If a \strong{function}, it is used as is.
If a \strong{formula}, e.g. \code{~ .x + 2}, it is converted to a function.
No longer recommended.
If \strong{character vector}, \strong{numeric vector}, or \strong{list}, it is
converted to an extractor function. Character vectors index by
name and numeric vectors index by position; use a list to index
by position and name at different levels. If a component is not
present, the value of \code{.default} will be returned.}
\item{...}{Additional arguments passed on to methods.}
\item{.default, .null}{Optional additional argument for extractor functions
(i.e. when \code{.f} is character, integer, or list). Returned when
value is absent (does not exist) or empty (has length 0).
\code{.null} is deprecated; please use \code{.default} instead.}
}
\description{
\code{as_mapper} is the powerhouse behind the varied function
specifications that most purrr functions allow. It is an S3
generic. The default method forwards its arguments to
\code{\link[rlang:as_function]{rlang::as_function()}}.
}
\examples{
as_mapper(\(x) x + 1)
as_mapper(1)
as_mapper(c("a", "b", "c"))
# Equivalent to function(x) x[["a"]][["b"]][["c"]]
as_mapper(list(1, "a", 2))
# Equivalent to function(x) x[[1]][["a"]][[2]]
as_mapper(list(1, attr_getter("a")))
# Equivalent to function(x) attr(x[[1]], "a")
as_mapper(c("a", "b", "c"), .default = NA)
}