the difference between closure and builtin

example:

f <- function(){}
typeof(f)
## [1] "closure"
# > "closure"
typeof(sum)
## [1] "builtin"
# > "builtin"

mode() is just a shadow of typeof()

To see if an object is a pure base type, i.e., it doesn’t also have S3, S4, or RC behaviour, check that is.object(x) returns FALSE.

Check Static Class by otype() and ftype()

In S3, methods belong to functions, called generic functions, or generics for short. S3 methods do not belong to objects or classes. This is different from most other programming languages, but is a legitimate OO style.

x = seq(10)
y = rep(1,10)
t = data.frame(x,y)
otype(x)
## Error in eval(expr, envir, enclos): could not find function "otype"
# > "base"
otype(t)
## Error in eval(expr, envir, enclos): could not find function "otype"
# > "S3"

ftype(sum)
## Error in eval(expr, envir, enclos): could not find function "ftype"
# > [1] "primitive" "generic"

ftype(mean)
## Error in eval(expr, envir, enclos): could not find function "ftype"
# > [1] "s3"      "generic"

methods("mean")
## [1] mean.Date     mean.default  mean.difftime mean.POSIXct 
## [5] mean.POSIXlt 
## see '?methods' for accessing help and source code
# > [1] mean.Date     mean.default  mean.difftime mean.POSIXct  mean.POSIXlt
foo <- structure(list(), class = "foo")
# 1. Pipe to first-argument of function
rnorm(100) %>>%
  plot
## Error in eval(expr, envir, enclos): could not find function "%>>%"
# 
# 2. Pipe to . in an expression
# 
rnorm(100) %>>%
  plot(col="red", main=length(.))
## Error in eval(expr, envir, enclos): could not find function "%>>%"
# pass left side result into right side point.

a[1, , drop = FALSE]