Skip to contents

Converts a character vector (or anything as.character() accepts) to a charpack, copying its strings. If x is already a charpack it is returned unchanged. Names are preserved; other attributes are dropped.

Usage

as_charpack(x)

Arguments

x

object to convert.

Value

A charpack (an ALTREP character vector).

Details

A charpack stays compact while it is read through charport, and vector subsets such as x[i] stay packed. Reading individual strings from R, such as x[[1]] or print(x), extracting matrix columns, or modifying elements materializes the whole vector. This makes it mainly useful for testing code that reads strings through charport.

Examples

x <- as_charpack(c("a", NA, "b"))
is_charpack(x)
#> [1] TRUE