TYPEOF.Rd
TYPEOF
is a function-like macro that determines the type of an
SEXPREC
object.
x | an |
---|
A SEXPTYPE
value.
#define TYPEOF(x) ((x)->sxpinfo.type)
In Rinternals.h.
# Determine R objects' SEXPTYPEs sexptype <- inline::cfunction(c(x = "ANY"), ' SEXP type_value; type_value = PROTECT(Rf_ScalarInteger(TYPEOF(x))); UNPROTECT(1); return type_value; ' SEXP type_value; type_value = PROTECT(Rf_ScalarInteger(TYPEOF(x))); UNPROTECT(1); return type_value; ') # NULL, returns 0 sexptype(NULL)#> [1] 0#> [1] 0#> [1] 1#> [1] 2# closure, returns 3 sexptype(function(x) {x + 1})#> [1] 3# environment, returns 4 sexptype(.GlobalEnv)#> [1] 4# promises, returns 5 # But how to get one? # language (call and formulae), returns 6 sexptype(call("sin", pi))#> [1] 6sexptype(~ x + 2)#> [1] 6# special forms, returns 7 sexptype(.Internal)#> [1] 7#> [1] 8# "scalar" string type (internal only), would return 9 # No way of getting hold of one of this in R land # logical vectors, returns 10 sexptype(TRUE)#> [1] 10sexptype(FALSE)#> [1] 10sexptype(NA)#> [1] 10# codes 12 and 13 are no longer in use # used to be for factors and ordered factors in the 1990s # integer vectors, returns 13 sexptype(1L)#> [1] 13#> [1] 13# real vectors, returns 14 sexptype(1)#> [1] 14sexptype(pi)#> [1] 14#> [1] 14#> [1] 14# complex vectors, returns 15 sexptype(1i)#> [1] 15sexptype(0i)#> [1] 15sexptype(0 + 1i)#> [1] 15sexptype(NA_complex_)#> [1] 15# string vectors , returns 16 sexptype("alice in wonderland")#> [1] 16# TODO: dot-dot-dot object, returns 17 # TODO: "any" args, returns 18 # generic vectors, i.e., lists, returns 19 sexptype(list())#> [1] 19#> [1] 20# TODO: byte code, returns 21 # TODO: external pointer, returns 22 # TODO: weak reference, returns 23 # raw bytes, returns 24 sexptype(raw(2))#> [1] 24# TODO: S4, non-vector, returns 25 # TODO: fresh node created in new page, returns 30 # TODO: node released by GC, returns 31 # TODO: Closure or Builtin or Special, returns 99