[英]Why does formals function return NULL on functions defined with arguments?
From base R , formals function should grant access and allow manipulation of the Formal Arguments. 从基R, 缩甲醛函数应当准许访问,并允许形参的操纵。 So, why does it return NULL on some functions defined with classic arguments ?
那么,为什么在某些用经典参数定义的函数上返回NULL呢?
> ls
function (name, pos = -1L, envir = as.environment(pos), all.names = FALSE,
pattern, sorted = TRUE)
{ ...
> formals(ls)
$name
$pos
-1L
$envir
as.environment(pos)
$all.names
[1] FALSE
$pattern
$sorted
[1] TRUE
> sum
function (..., na.rm = FALSE) .Primitive("sum")
> formals(sum)
NULL
I expect formals(sum) to provide a length two list result, not NULL 我期望formals(sum)提供两个列表的长度结果,而不是NULL
The problem with your choice of function is apparent from its body. 选择功能的问题从其身体上显而易见。 Primitive functions are somewhat different in that their argument list may have some names but their arguments are passed to C code and
formals()
, body()
, and environment()
all return NULL
. 原始函数有些不同,因为它们的参数列表可能有一些名称,但是它们的参数传递给C代码,而
formals()
, body()
和environment()
都返回NULL
。 Try it with apply
instead. 尝试使用
apply
代替。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.