Hi,
I've been trying to build a simple test vector (reprex below).
What I'm struggling to understand is that if I want a vector of the same object type (or in particular a named vector of toy_vector), this doesn't seem to work. If I call new_toy_vector once but provide parameters with length two (ie. new_toy_vector(c("Hello", "World"), c("Test", "Test2")) that would work fine, but would make illegible code for the vector I'm trying to create.
Could anyone guide me where I'm going wrong?
new_toy_vector <- function(
x = character(),
descriptor = character()) {
vctrs::vec_assert(x,character())
vctrs::vec_assert(descriptor, character())
vctrs::new_vctr(x,
descriptor = descriptor,
class = "toy_vector")
}
setOldClass(c("toy_vector", "vctrs_vctr"))
format.toy_vector <- function(x, ...) {
paste0(vctrs::vec_data(x)," is ", attr(x, "descriptor"))
}
obj_print_data.toy_vector <- function(x) {
cat(format(x), sep = "\n")
}
c(new_toy_vector("Hello", "Foo"), new_toy_vector("World", "Bar"))
#> Error: No common type for `..1` <toy_vector> and `..2` <toy_vector>.
Created on 2020-04-26 by the reprex package (v0.3.0)