The R Project SVN R

Rev

Rev 56186 | Rev 59039 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 56186 Rev 58825
Line 1... Line 1...
1
% File src/library/base/man/function.Rd
1
% File src/library/base/man/function.Rd
2
% Part of the R package, http://www.R-project.org
2
% Part of the R package, http://www.R-project.org
3
% Copyright 1995-2007 R Core Development Team
3
% Copyright 1995-2012 R Core Development Team
4
% Distributed under GPL 2 or later
4
% Distributed under GPL 2 or later
5
 
5
 
6
\name{function}
6
\name{function}
-
 
7
\alias{function}
-
 
8
\alias{return}
-
 
9
\alias{closure}
-
 
10
 
7
\title{Function Definition}
11
\title{Function Definition}
8
\usage{
12
\usage{
9
\special{function( arglist ) expr}
13
\special{function( arglist ) expr}
10
\special{return(value)}
14
\special{return(value)}
11
}
15
}
12
\alias{function}
-
 
13
\alias{return}
-
 
14
\description{
16
\description{
15
  These functions provide the base mechanisms for defining
17
  These functions provide the base mechanisms for defining
16
  new functions in the \R language.
18
  new functions in the \R language.
17
}
19
}
18
\arguments{
20
\arguments{
19
    \item{arglist}{Empty or one or more name or name=expression terms.}
21
    \item{arglist}{Empty or one or more name or name=expression terms.}
-
 
22
    \item{expr}{An expression.}
20
    \item{value}{An expression.}
23
    \item{value}{An expression.}
21
}
24
}
22
\details{
25
\details{
23
  The names in an argument list can be back-quoted non-standard names
26
  The names in an argument list can be back-quoted non-standard names
24
  (see \sQuote{\link{backquote}}).
27
  (see \sQuote{\link{backquote}}).
Line 30... Line 33...
30
  \code{\link{on.exit}} expression is evaluated.)
33
  \code{\link{on.exit}} expression is evaluated.)
31
  
34
  
32
  If the end of a function is reached without calling \code{return}, the
35
  If the end of a function is reached without calling \code{return}, the
33
  value of the last evaluated expression is returned.
36
  value of the last evaluated expression is returned.
34
}
37
}
-
 
38
 
35
\section{Warning}{
39
\section{Technical details}{
36
  Prior to \R 1.8.0, \code{value} could be a series of non-empty
40
  This type of function is not the only type in \R: they are called
37
  expressions separated by commas.  In that case the value
41
  \emph{closures} (a name with origins in LISP) to distinguish them from
-
 
42
  \link{primitive} functions.
-
 
43
 
38
  returned is a list of the evaluated expressions, with names set to
44
  A closure has three components, its \code{\link{formals}} (its argument
39
  the expressions where these are the names of \R objects.  That is,
45
  list), its \code{\link{body}} (\code{expr} in the \sQuote{Usage}
40
  \code{a=foo()} names the list component \code{a} and gives it the value
46
  section) and its \code{\link{environment}} which provides the
41
  which results from evaluating \code{foo()}.
47
  enclosure of the evaluation frame when the closure is used.
42
 
48
 
43
  This has been deprecated (and a warning is given), as it was never
49
  There is an optional further component if the closure has been
44
  documented in S, and whether or not the list is named differs by S
50
  byte-compiled.  This is not normally user-visible, but it indicated
45
  versions.  Supply a (named) list \code{value} instead.
51
  when functions are printed.
46
}
52
}
-
 
53
 
47
\seealso{
54
\seealso{
-
 
55
  \code{\link{args}}.
-
 
56
 
48
  \code{\link{args}} and \code{\link{body}} for accessing the arguments
57
  \code{\link{formals}}, \code{\link{body}} and
-
 
58
  \code{\link{environment}} for accessing the component parts of a
49
  and body of a function.
59
  function.
50
 
60
 
51
  \code{\link{debug}} for debugging; using \code{\link{invisible}} inside
61
  \code{\link{debug}} for debugging; using \code{\link{invisible}} inside
52
  \code{return(.)} for returning \emph{invisibly}.
62
  \code{return(.)} for returning \emph{invisibly}.
53
}
63
}
54
\references{
64
\references{