Macro function-like

TYPEOF is a function-like macro that determines the type of an SEXPREC object.

Arguments

x

an SEXP pointer.

Value

A SEXPTYPE value.

Declaration

#define TYPEOF(x) ((x)->sxpinfo.type)

In Rinternals.h.

See also

Examples

# 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
# an empty pairlist also returns 0 sexptype(pairlist())
#> [1] 0
# symbol, returns 1 sexptype(as.symbol('a'))
#> [1] 1
# dotted pair list, returns 2 sexptype(pairlist(a = 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] 6
sexptype(~ x + 2)
#> [1] 6
# special forms, returns 7 sexptype(.Internal)
#> [1] 7
# builtin non-special forms, returns 8 sexptype(.Primitive("sqrt"))
#> [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] 10
sexptype(FALSE)
#> [1] 10
sexptype(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
sexptype(factor('as')) # still an integer vector
#> [1] 13
# real vectors, returns 14 sexptype(1)
#> [1] 14
sexptype(pi)
#> [1] 14
sexptype(double(1))
#> [1] 14
sexptype(numeric(1))
#> [1] 14
# complex vectors, returns 15 sexptype(1i)
#> [1] 15
sexptype(0i)
#> [1] 15
sexptype(0 + 1i)
#> [1] 15
sexptype(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
# expression, returns 20 sexptype(expression(x + 2))
#> [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