rattr: Set and get attributes of the original R-vector stored in an...

View source: R/attr.R

rattrR Documentation

Set and get attributes of the original R-vector stored in an lvec

Description

Set and get attributes of the original R-vector stored in an lvec

Usage

rattr(x, which)

rattr(x, which) <- value

Arguments

x

and object of type lvec

which

a character vector of length one giving the name of the attribute.

value

the new value of the attribute

Details

The attributes of the lvec can be set and obtained using the standard functions attr and attributes. However when an lvec is converted to an R-vector using, for example, as_rvec, the attributes of the resulting R-vector are set using the result of rattr. This can be used to store vectors such as factors and dates (POSIXct) in lvec objects, as these are basically integer and numeric vectors with a number of additional attributes.

Examples

dates <- as_lvec(as.Date("2016-12-05", "2016-12-24"))
# When printing and reading the result is converted back to a date object
print(dates)
as_rvec(dates)

# make a factor of an integer lvec 
a <- as_lvec(1:3)
rattr(a, "class") <- "factor"
rattr(a, "levels") <- c("a", "b", "c")
print(a)


lvec documentation built on Nov. 10, 2022, 6:18 p.m.

Related to rattr in lvec...