File: function_new.Rd

package info (click to toggle)
r-cran-lazyeval 0.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 596 kB
  • sloc: ansic: 310; sh: 9; makefile: 2
file content (39 lines) | stat: -rw-r--r-- 1,213 bytes parent folder | download | duplicates (2)
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
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/function.R
\name{function_new}
\alias{function_new}
\title{Create a function by "hand"}
\usage{
function_new(args, body, env = parent.frame())
}
\arguments{
\item{args}{A named list of default arguments.  Note that if you want
arguments that don't have defaults, you'll need to use the special function
\code{\link{alist}}, e.g. \code{alist(a = , b = 1)}}

\item{body}{A language object representing the code inside the function.
Usually this will be most easily generated with \code{\link{quote}}}

\item{env}{The parent environment of the function, defaults to the calling
environment of \code{make_function}}
}
\description{
This constructs a new function given it's three components:
list of arguments, body code and parent environment.
}
\examples{
f <- function(x) x + 3
g <- function_new(alist(x = ), quote(x + 3))

# The components of the functions are identical
identical(formals(f), formals(g))
identical(body(f), body(g))
identical(environment(f), environment(g))

# But the functions are not identical because f has src code reference
identical(f, g)

attr(f, "srcref") <- NULL
# Now they are:
stopifnot(identical(f, g))
}