Learn R Programming

insight (version 0.18.6)

trim_ws: Small helper functions

Description

Collection of small helper functions. trim_ws() is an efficient function to trim leading and trailing whitespaces from character vectors or strings. n_unique() returns the number of unique values in a vector. safe_deparse() is comparable to deparse1(), i.e. it can safely deparse very long expressions into a single string. safe_deparse_symbol() only deparses a substituted expressions when possible, which can be much faster than deparse(substitute()) for those cases where substitute() returns no valid object name.

Usage

trim_ws(x, ...)

# S3 method for data.frame trim_ws(x, character_only = TRUE, ...)

n_unique(x, ...)

# S3 method for default n_unique(x, na.rm = TRUE, ...)

safe_deparse(x, ...)

safe_deparse_symbol(x)

Value

For a vector, n_unique always returns an integer value, even if the input is NULL (the return value will be 0 then). For data frames or lists, n_unique() returns a named numeric vector, with the number of unique values for each element.

Arguments

x

A (character) vector, or for some functions may also be a data frame.

...

Currently not used.

character_only

Logical, if TRUE and x is a data frame or list, only processes character vectors.

na.rm

Logical, if missing values should be removed from the input.

Examples

Run this code
trim_ws("  no space!  ")
n_unique(iris$Species)

Run the code above in your browser using DataLab