检查函数是否是 R 编程中的原始函数- is.primitive()函数
R 语言中的is.primitive()
函数用于检查函数是否是原始函数,即它是内置函数还是特殊函数。
Syntax: is.primitive(func)
Parameters:
func: Function to be checked
示例 1:
# R program to illustrate
# the use of is.primitive function
# Calling is.primitive() function
is.primitive(1)
is.primitive(is.primitive)
is.primitive(sum)
is.primitive(prod)
输出:
[1] FALSE
[1] FALSE
[1] TRUE
[1] TRUE
示例 2:
# R program to illustrate
# the use of is.primitive function
# Sample user-defined Function
evenOdd = function(x){
if(x %% 2 == 0)
return("even")
else
return("odd")
}
# Calling is.primitive() function
is.primitive(evenOdd)
输出:
[1] FALSE