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

Description Usage Arguments Details Examples

View source: R/attr.R

Description

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

Usage

1
2
3
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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 May 2, 2019, 8:16 a.m.