int_period_class: Integer-period class (Experimental)

int_period_classR Documentation

Integer-period class (Experimental)

Description

⁠<grates_int_period>⁠ objects represent groupings of n consecutive integers from 0.

Usage

## Default S3 method:
as_int_period(x, n = 1L, ...)

## S3 method for class 'integer'
as_int_period(x, n = 1L, ...)

## S3 method for class 'double'
as_int_period(x, n = 1L, ...)

new_int_period(x = integer(), n = 1L)

is_int_period(xx)

as_int_period(x, n, ...)

Arguments

x, xx

R objects.

For as_int_period() this is the object to be coerced.

For new_int_period() this represents the number of n integer periods from 0.

double vectors will be converted via as.integer(floor(x)).

n

⁠[integer]⁠

Number of integers that are being grouped. Must be greater than 0.

...

Not currently used.

Details

as_int_period() is a generic for coercing input in to ⁠<grates_int_period>⁠ objects. For numeric input it coerces it's input x first via x <- as.integer(floor(x)) and then via integer division by n (i.e. x %/% n).

new_int_period() is a minimal constructor for ⁠<grates_period>⁠ objects aimed at developers. It takes, as input, the number of integer periods and the value of n.

Value

A ⁠<grates_int_period>⁠ object.

Examples


# coercion
as_int_period(1:10, n = 3)

# direct construction
stopifnot(
    identical(
        as_int_period(1:10, n = 3),
        new_int_period(c(0, 0, 1, 1, 1, 2, 2, 2, 3, 3), n = 3)
    )
)




grates documentation built on April 3, 2025, 10:49 p.m.