View | Details | Raw Unified | Return to bug 15715
Collapse All | Expand All

(-)src/library/base/man/call.Rd (-5 / +9 lines)
Lines 17-31 Link Here
17
as.call(x)
17
as.call(x)
18
}
18
}
19
\arguments{
19
\arguments{
20
  \item{name}{a non-empty character string naming the function to be called.}
20
  \item{name}{a non-empty character string or symbol naming the
21
  function to be called, or a function.}
21
  \item{\dots}{arguments to be part of the call.}
22
  \item{\dots}{arguments to be part of the call.}
22
  \item{x}{an arbitrary \R object.}
23
  \item{x}{an arbitrary \R object.}
23
}
24
}
24
\details{
25
\details{
25
  \code{call} returns an unevaluated function call, that is, an
26
  \code{call} returns an unevaluated function call, that is, an
26
  unevaluated expression which consists of the named function applied to
27
  unevaluated expression which consists of the named function applied to
27
  the given arguments (\code{name} must be a quoted string which gives
28
  the given arguments.  Note that although the call is
28
  the name of a function to be called).  Note that although the call is
29
  unevaluated, the arguments \code{\dots} are evaluated.
29
  unevaluated, the arguments \code{\dots} are evaluated.
30
30
31
  \code{call} is a primitive, so the first argument is
31
  \code{call} is a primitive, so the first argument is
Lines 76-84 Link Here
76
call("round", quote(A)) # round(A)
76
call("round", quote(A)) # round(A)
77
f <- "round"
77
f <- "round"
78
call(f, quote(A))       # round(A)
78
call(f, quote(A))       # round(A)
79
## if we want to supply a function we need to use as.call or similar
79
f <- quote(round)
80
call(f, quote(A))       # round(A)
81
## provide function directly
82
call(round, quote(A))   # .Primitive("round")(A)
83
80
f <- round
84
f <- round
81
\dontrun{call(f, quote(A))  # error: first arg must be character}
82
(g <- as.call(list(f, quote(A))))
85
(g <- as.call(list(f, quote(A))))
83
eval(g)
86
eval(g)
84
## alternatively but less transparently
87
## alternatively but less transparently
Lines 86-91 Link Here
86
mode(g) <- "call"
89
mode(g) <- "call"
87
g
90
g
88
eval(g)
91
eval(g)
92
89
## see also the examples in the help for do.call
93
## see also the examples in the help for do.call
90
}
94
}
91
\keyword{programming}
95
\keyword{programming}
(-)src/main/coerce.c (-20 / +12 lines)
Lines 2360-2390 Link Here
2360
    return ans;
2360
    return ans;
2361
}
2361
}
2362
2362
2363
/* This is a primitive SPECIALSXP */
2364
SEXP attribute_hidden do_call(SEXP call, SEXP op, SEXP args, SEXP rho)
2363
SEXP attribute_hidden do_call(SEXP call, SEXP op, SEXP args, SEXP rho)
2365
{
2364
{
2366
    SEXP rest, evargs, rfun, tmp;
2365
    SEXP rest, rfun;
2367
2368
    if (length(args) < 1) errorcall(call, _("'name' is missing"));
2366
    if (length(args) < 1) errorcall(call, _("'name' is missing"));
2369
    check1arg(args, call, "name");
2367
    check1arg(args, call, "name");
2370
    PROTECT(rfun = eval(CAR(args), rho));
2368
    rfun = CAR(args);
2371
    /* zero-length string check used to be here but install gives
2369
    if (isString(rfun) && length(rfun) == 1) {
2372
       better error message.
2370
        const char *str = translateChar(STRING_ELT(rfun, 0));
2373
     */
2371
        if (streql(str, ".Internal")) error("illegal usage");
2374
    if (!isString(rfun) || length(rfun) != 1)
2372
        PROTECT(rfun = install(str));
2375
	errorcall_return(call, _("first argument must be a character string"));
2373
    } else if (isFunction(rfun) || isSymbol(rfun)) {
2376
    const char *str = translateChar(STRING_ELT(rfun, 0));
2374
        PROTECT(rfun = lazy_duplicate(rfun));
2377
    if (streql(str, ".Internal")) error("illegal usage");
2375
    } else {
2378
    PROTECT(rfun = install(str));
2376
        errorcall_return(call, _("'name' must be a string, function or symbol"));
2379
    PROTECT(evargs = duplicate(CDR(args)));
2380
    for (rest = evargs; rest != R_NilValue; rest = CDR(rest)) {
2381
	PROTECT(tmp = eval(CAR(rest), rho));
2382
	if (MAYBE_REFERENCED(tmp)) tmp = duplicate(tmp);
2383
	SETCAR(rest, tmp);
2384
	UNPROTECT(1);
2385
    }
2377
    }
2386
    rfun = LCONS(rfun, evargs);
2378
    rfun = LCONS(rfun, shallow_duplicate(CDR(args)));
2387
    UNPROTECT(3);
2379
    UNPROTECT(1);
2388
    return (rfun);
2380
    return (rfun);
2389
}
2381
}
2390
2382
(-)src/main/names.c (-1 / +1 lines)
Lines 117-123 Link Here
117
{".primUntrace",do_trace,	1,	101,	1,	{PP_FUNCALL, PREC_FN,	  0}},
117
{".primUntrace",do_trace,	1,	101,	1,	{PP_FUNCALL, PREC_FN,	  0}},
118
{".Internal",	do_internal,	0,	200,	1,	{PP_FUNCALL, PREC_FN,	  0}},
118
{".Internal",	do_internal,	0,	200,	1,	{PP_FUNCALL, PREC_FN,	  0}},
119
{".Primitive",	do_primitive,	0,	1,	1,	{PP_FUNCALL, PREC_FN,	  0}},
119
{".Primitive",	do_primitive,	0,	1,	1,	{PP_FUNCALL, PREC_FN,	  0}},
120
{"call",	do_call,	0,	0,	-1,	{PP_FUNCALL, PREC_FN,	0}},
120
{"call",	do_call,	0,	1,	-1,	{PP_FUNCALL, PREC_FN,	0}},
121
{"quote",	do_quote,	0,	0,	1,	{PP_FUNCALL, PREC_FN,	0}},
121
{"quote",	do_quote,	0,	0,	1,	{PP_FUNCALL, PREC_FN,	0}},
122
{"substitute",	do_substitute,	0,	0,	-1,	{PP_FUNCALL, PREC_FN,	0}},
122
{"substitute",	do_substitute,	0,	0,	-1,	{PP_FUNCALL, PREC_FN,	0}},
123
{"missing",	do_missing,	1,	0,	1,	{PP_FUNCALL, PREC_FN,	0}},
123
{"missing",	do_missing,	1,	0,	1,	{PP_FUNCALL, PREC_FN,	0}},

Return to bug 15715