The R Project SVN R

Rev

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

Rev 24322 Rev 24330
Line 5... Line 5...
5
return(value)
5
return(value)
6
}
6
}
7
\alias{function}
7
\alias{function}
8
\alias{return}
8
\alias{return}
9
\description{
9
\description{
10
These functions provide the base mechanisms for defining
10
  These functions provide the base mechanisms for defining
11
new functions in the \R language.
11
  new functions in the \R language.
12
}
12
}
13
\arguments{
13
\arguments{
14
    \item{arglist}{Empty or one or more name or name=expression terms.}
14
    \item{arglist}{Empty or one or more name or name=expression terms.}
15
    \item{value}{An expression, or a series of non-empty expressions separated
15
    \item{value}{An expression.}
16
        by commas.}
-
 
17
}
16
}
18
\details{
17
\details{
19
    In \R (unlike S) the names in an argument list cannot be quoted
18
  In \R (unlike S) the names in an argument list cannot be quoted
20
    non-standard names.
19
  non-standard names.
21
 
20
 
22
    If \code{value} is missing, \code{NULL} is returned.  If it is a
21
  If \code{value} is missing, \code{NULL} is returned.  If it is a
23
    single expression, the value of the evaluated expression is returned.
22
  single expression, the value of the evaluated expression is returned.
24
 
23
 
-
 
24
  If the end of a function is reached without calling \code{return}, the
-
 
25
  value of the last evaluated expression is returned.
-
 
26
}
-
 
27
\section{Warning}{
25
    If \code{value} is a series of non-empty expressions, the value
28
  Prior to \R 1.8.0, \code{value} could be a series of non-empty
-
 
29
  expressions separated by commas.  In that case the value
26
    returned is a list of the evaluated expressions, with names set to
30
  returned is a list of the evaluated expressions, with names set to
27
    the expressions where these are the names of \R objects. That is,
31
  the expressions where these are the names of \R objects. That is,
28
    \code{a=foo()} names the list component \code{a} and gives it value
32
  \code{a=foo()} names the list component \code{a} and gives it value
29
    the result of evaluating \code{foo()}.
33
  the result of evaluating \code{foo()}.
30
 
34
 
-
 
35
  This has been deprecated (and a warning is given), as it was never
-
 
36
  documented in S, and whether or not the list is named differs by S versions.
31
}
37
}
32
\seealso{
38
\seealso{
33
  \code{\link{args}} and \code{\link{body}} for accessing the arguments
39
  \code{\link{args}} and \code{\link{body}} for accessing the arguments
34
  and body of a function.
40
  and body of a function.
35
 
41
 
36
  \code{\link{debug}} for debugging; \code{\link{invisible}} for
42
  \code{\link{debug}} for debugging; \code{\link{invisible}} for
37
  \code{return(.)}ing \emph{invisibly}.
43
  \code{return(.)}ing \emph{invisibly}.
38
}
44
}
-
 
45
\references{
-
 
46
  Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
-
 
47
  \emph{The New S Language}.
-
 
48
  Wadsworth \& Brooks/Cole.
-
 
49
}
39
\examples{
50
\examples{
40
norm <- function(x) sqrt(x\%*\%x)
51
norm <- function(x) sqrt(x\%*\%x)
41
norm(1:4)
52
norm(1:4)
42
 
53
 
43
## An anonymous function:
54
## An anonymous function: