as_mmm: Coerce to base mode or 'extended mode'

View source: R/as_mmm.R

as_mmmR Documentation

Coerce to base mode or extended mode

Description

Functions to coerce objects to base mode or extended mode.

Usage

as_mmm(x, mode, levs = NULL, na = FALSE)

as_chr(x, na = FALSE)

as_clr(x, na = FALSE)

as_fun(x)

as_int(x)

as_num(x)

as_lgl(x)

as_ord(x, levs)

as_uno(x, levs)

Arguments

x

For as_clr, an object of mode character; for as_fun, a character scalar function name or a function object; for as_ord and as_uno, an atomic object; and for all others, any R object.

mode

A threechar scalar containing an extended mode value.

levs

Optional complete atomic vec of factor levels (ordered factor levels for as_ord).

na

TRUE or FALSE indicating whether NA values are acceptable.

Details

Functions in this family are as follows:

  as_chr   Thinly wraps as.character.
  as_int Thinly wraps as.integer.
  as_num Thinly wraps as.numeric.
  as_lgl Thinly wraps as.logical.
   
  as_ord As extended mode 'ord' (ordered factor). Wraps factor(x, levels = levs, ordered = TRUE).
   
  as_uno As extended mode 'uno' (unordered factor). Wraps factor(x, levels = levs, ordered = FALSE).
   
  as_clr Coerces character color values to hexadecimal.
   
  as_fun If x is a character scalar function return that function, but if x is a function object, return it.

Value

An object of base mode 'character'

as_chr

An object of base mode 'integer'

as_int

An object of base mode 'logical'

as_lgl

An object of base mode 'numeric'

as_num

An object of extended mode 'ord' (ordered factor)

as_ord

An object of extended mode 'uno' (unordered factor)

as_uno

An object of extended mode 'clr' (hex color in form '#RRGGBBAA')

as_clr

See Also

Other properties: bbb_ccc_help(), bbb_help(), bbb_mmm_prop_funs(), ccc_help(), cls(), cmp_ccc_help(), cmp_mmm_ccc_help(), cmp_mmm_help(), compatible(), ddd_prop_funs(), eee_help(), iii_help(), meets(), mmm_ccc_help(), mmm_help(), ppp_fast_help(), ppp_help(), sss_ccc_help(), sss_prop_funs(), unq_ccc_prop_funs(), unq_mmm_ccc_help(), unq_mmm_help()

Examples

bins. <- sample(c(0, 1), 10, replace = T)
chrs. <- c("3.14", "2.72", "1.41")
clrs. <- c("red", "#AABBCC", "#AABBCCDD", "blue")
nums. <- c(pi, exp(1), sqrt(2))

as_fun(unique)
as_fun("unique")

bins.
as_lgl(bins.)

chrs.
as_num(chrs.)
as_int(chrs.)

clrs.
as_clr(clrs.)

nums.
as_chr(nums.)

as_uno(clrs., levs = unique(clrs.))
as_ord(clrs., levs = sort(unique(clrs.)))

j-martineau/uj documentation built on Sept. 14, 2024, 4:40 a.m.