library/vctrs/NEWS.md

vctrs 0.2.0

With the 0.2.0 release, many vctrs functions have been rewritten with native C code to improve performance. Functions like vec_c() and vec_rbind() should now be fast enough to be used in packages. This is an ongoing effort, for instance the handling of factors and dates has not been rewritten yet. These classes still slow down vctrs primitives.

The API in 0.2.0 has been updated, please see a list of breaking changes below. vctrs has now graduated from experimental to a maturing package (see the lifecycle of tidyverse packages). Please note that API changes are still planned for future releases, for instance vec_ptype2() and vec_cast() might need to return a sentinel instead of failing with an error when there is no common type or possible cast.

Breaking changes

`` vec_c(foo = c(a = 1)) #> Error: Can't merge the outer namefoowith a named vector. #> Please supply a.name_spec` specification.

vec_c(foo = 1:3) #> Error: Can't merge the outer name foo with a vector of length > 1. #> Please supply a .name_spec specification. ```

You can supply a name specification that describes how to combine the external name of the input with its internal names or positions:

``` # Name spec as glue string: vec_c(foo = c(a = 1), .name_spec = "{outer}_{inner}")

# Name spec as a function: vec_c(foo = c(a = 1), .name_spec = function(outer, inner) paste(outer, inner, sep = "")) vec_c(foo = c(a = 1), .name_spec = ~ paste(.x, .y, sep = "")) ```

Consequently, vec_ptype() was renamed to vec_ptype_show().

New features

The most common case where you need to implement vec_proxy() is for S3 lists. In vctrs, S3 lists are treated as scalars by default. This way we don't treat objects like model fits as vectors. To prevent vctrs from treating your S3 list as a scalar, unclass it from the vec_proxy() method. For instance here is the definition for list_of:

#' @export vec_proxy.vctrs_list_of <- function(x) { unclass(x) }

If you inherit from vctrs_vctr or vctrs_rcrd you don't need to implement vec_proxy().

``` df1 <- tibble(foo = tibble(bar = tibble(x = 1:3, y = letters[1:3]))) df2 <- tibble(foo = tibble(bar = tibble(x = 1:3, y = 4:6)))

vec_rbind(df1, df2) #> Error: No common type for ..1$foo$bar$y and ..2$foo$bar$y . ```

r data <- tibble::tibble(x = 1:3, y = letters[1:3]) data <- vec_cbind(data, packed = data) data # A tibble: 3 x 3 x y packed$x $y <int> <chr> <int> <chr> 1 1 a 1 a 2 2 b 2 b 3 3 c 3 c

Packed data frames are nested in a single column. This makes it possible to access it through a single name:

r data$packed # A tibble: 3 x 2 x y <int> <chr> 1 1 a 2 2 b 3 3 c

We are planning to use this syntax more widely in the tidyverse.

Called without a specific type or size, vec_assert() tests whether an object is a data vector or a scalar. S3 lists are treated as scalars by default. Implement a vec_is_vector() for your class to override this property (or derive from vctrs_vctr).

Other features and bug fixes



OllieFord/ChangepointVis documentation built on Aug. 26, 2019, 7:53 p.m.