Learn R Programming

vetr (version 0.2.19)

type_of: Fuzzily Compare Types of Objects

Description

Type evaluation and comparison is carried out with special treatment for numerics, integers, and function types. Whole number NA-free numeric vectors of sufficiently short length (<100 by default) representable in the integer type are considered to be type integer. Closures, built-ins, and specials are all treated as type closure.

Usage

type_of(object)

type_alike(target, current, settings = NULL)

Value

For type_of character(1L) the type of the object, for type_alike

either TRUE, or a string describing why the types are not alike.

Arguments

object

the object to check the type of

target

the object to test type alikeness against

current

the object to test the type alikeness of

settings

NULL, or a list as produced by vetr_settings()

Details

Specific behavior can be tuned with the type.mode parameter to the vetr_settings() object passed as the settings parameter to this function.

See Also

alike(), vetr_settings(), in particular the section about the type.mode parameter which affects how this function behaves.

Examples

Run this code
type_of(1.0001)          # numeric
type_of(1.0)             # integer (`typeof` returns numeric)
type_of(1)               # integer (`typeof` returns numeric)
type_of(sum)             # closure (`typeof` returns builtin)
type_of(`$`)             # closure (`typeof` returns special)

type_alike(1L, 1)
type_alike(1L, 1.1)
type_alike(integer(), numeric(100))
type_alike(integer(), numeric(101))  # too long

Run the code above in your browser using DataLab