Skip to content

vec_c() for S4 classes #919

Description

@krlmlr

Introduced in #803, breaks as of d8efb4f, works in 361667d = d8efb4f^.

.rando <- setClass("rando", contains = "numeric", slots = list(.Data = "numeric"))
rando <- function(n = 0) {
  .rando(as.numeric(seq_len(n)))
}

as_rando <- function(x) {
  rando(length(x))
}

setMethod("[", "rando", function(x, i, j, ..., drop = TRUE) {
  new_n <- length(vec_as_location(i, length(x@.Data), names(x@.Data)))
  rando(new_n)
})


library(vctrs)
vec_c(rando(), rando())
#> Error: Can't find vctrs or base methods for concatenation.
#> vctrs methods must be implemented for class `rando`.
#> See <https://vctrs.r-lib.org/articles/s3-vector.html>.


library(lubridate)
#> 
#> Attaching package: 'lubridate'
#> The following object is masked from 'package:vctrs':
#> 
#>     new_duration
#> The following object is masked from 'package:base':
#> 
#>     date
x <- interval(today(), today())
vec_c(x, x)
#> Error: Can't find vctrs or base methods for concatenation.
#> vctrs methods must be implemented for class `Interval`.
#> See <https://vctrs.r-lib.org/articles/s3-vector.html>.

Created on 2020-03-15 by the reprex package (v0.3.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions