R: Cast values into shape

cast {forge} | R Documentation

## Cast values into shape

### Description

These functions verify and attempt to coerce values into the specified types and shapes. If they are unsuccessful in the coercion, an error is thrown.

### Usage

    cast_integer(x, n = NULL, allow_na = FALSE, allow_null = FALSE)

    cast_scalar_integer(x, allow_na = FALSE, allow_null = FALSE)

    cast_nullable_integer(x, n = NULL, allow_na = FALSE)

    cast_nullable_scalar_integer(x, allow_na = FALSE)

    cast_integer_list(x, n = NULL, allow_na = FALSE, allow_null = FALSE)

    cast_nullable_integer_list(x, n = NULL, allow_na = FALSE)

    cast_double(x, n = NULL, allow_na = FALSE, allow_null = FALSE)

    cast_scalar_double(x, allow_na = FALSE, allow_null = FALSE)

    cast_nullable_double(x, n = NULL, allow_na = FALSE)

    cast_nullable_scalar_double(x, allow_na = FALSE)

    cast_double_list(x, n = NULL, allow_na = FALSE, allow_null = FALSE)

    cast_nullable_double_list(x, n = NULL, allow_na = FALSE)

    cast_character(x, n = NULL, allow_na = FALSE, allow_null = FALSE)

    cast_scalar_character(x, allow_na = FALSE, allow_null = FALSE)

    cast_nullable_character(x, n = NULL, allow_na = FALSE)

    cast_nullable_scalar_character(x, allow_na = FALSE)

    cast_character_list(x, n = NULL, allow_na = FALSE,
      allow_null = FALSE)

    cast_nullable_character_list(x, n = NULL, allow_na = FALSE)

    cast_string(x, allow_na = FALSE, allow_null = FALSE)

    cast_nullable_string(x, allow_na = FALSE)

    cast_string_list(x, n = NULL, allow_na = FALSE, allow_null = FALSE)

    cast_nullable_string_list(x, n = NULL, allow_na = FALSE)

    cast_logical(x, n = NULL, allow_na = FALSE, allow_null = FALSE)

    cast_scalar_logical(x, allow_na = FALSE, allow_null = FALSE)

    cast_nullable_logical(x, n = NULL, allow_na = FALSE)

    cast_nullable_scalar_logical(x, allow_na = FALSE)

    cast_logical_list(x, n = NULL, allow_na = FALSE, allow_null = FALSE)

    cast_nullable_logical_list(x, n = NULL, allow_na = FALSE)

    cast_choice(x, choices, allow_na = FALSE, allow_null = FALSE)

### Arguments

`x` | A vector.
`n` | The required length of the vector. If `NULL`, the length is not checked.
`allow_na` | Whether to allow `NA`s in the vector.
`allow_null` | Whether to allow `NULL`.
`choices` | A character, numeric, or integer vector of allowed values.

### Examples

    # Cast a double vector to integer
    cast_integer(c(1, 2))

    # Cast a numeric to a string
    cast_string(4.5)

    # Cast an integer vector to a list of doubles
    cast_double_list(1:4)

[Package forge version 0.1.0 Index]