Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

type_of

Base type of an object


Description

Soft-deprecated lifecycleExperimental lifecycle

This is equivalent to base::typeof() with a few differences that make dispatching easier:

  • The type of one-sided formulas is "quote".

  • The type of character vectors of length 1 is "string".

  • The type of special and builtin functions is "primitive".

Usage

type_of(x)

Arguments

x

An R object.

Life cycle

type_of() is an experimental function. Expect API changes.

Examples

type_of(10L)

# Quosures are treated as a new base type but not formulas:
type_of(quo(10L))
type_of(~10L)

# Compare to base::typeof():
typeof(quo(10L))

# Strings are treated as a new base type:
type_of(letters)
type_of(letters[[1]])

# This is a bit inconsistent with the core language tenet that data
# types are vectors. However, treating strings as a different
# scalar type is quite helpful for switching on function inputs
# since so many arguments expect strings:
switch_type("foo", character = abort("vector!"), string = "result")

# Special and builtin primitives are both treated as primitives.
# That's because it is often irrelevant which type of primitive an
# input is:
typeof(list)
typeof(`$`)
type_of(list)
type_of(`$`)

rlang

Functions for Base Types and Core R and 'Tidyverse' Features

v0.4.11
MIT + file LICENSE
Authors
Lionel Henry [aut, cre], Hadley Wickham [aut], mikefc [cph] (Hash implementation based on Mike's xxhashlite), Yann Collet [cph] (Author of the embedded xxHash library), RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.