Using rcrd classes with purrr::pmap()

I am trying to create a rcrd-based class that will then be used in purrr::pmap() calls, but I am getting various errors that seem to come from some clash between the way length of elements is calculated?

How can I make my rcrd class work with purrr::pmap?

Example below uses the rational example from vctrs docs.

#> Warning: Paket 'vctrs' wurde unter R Version 4.0.2 erstellt

new_rational <- function(n = integer(), d = integer()) {
  vec_assert(n, ptype = integer())
  vec_assert(d, ptype = integer())
  new_rcrd(list(n = n, d = d), class = "vctrs_rational")

df <- tibble::tibble(
  aa = c(1L, 2L, 3L),
  bb = c(1L, 1L, 1L),
  cc = new_rational(aa, bb)

format.vctrs_rational <- function(x, ...) {
  n <- field(x, "n")
  d <- field(x, "d")
  out <- paste0(n, "/", d)
  out[ |] <- NA

t <- purrr::pmap(
  list(df$aa, df$bb, df$cc),
  function(x, y, z) list(x, y, z)
#> Error: Element 3 of `.l` must have length 1 or 3, not 3

Created on 2020-08-09 by the reprex package (v0.3.0)

The solution hinted at here works for me: wrap the object in as.list()

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.