rpurrrbit64

Return 64 bit integer from purrr::map_*


How do I return a 64-bit integer from purrr::map_*?

Below does not work

library(bit64)
library(tidyverse)

tibble(x=1:3) %>% 
  mutate(y=map_int(x,~{return(as.integer64(2^55))}))

Error in mutate(): ! Problem while computing y = map_int(...). Caused by error: ! Can't coerce element 1 from a double to a integer Run rlang::last_error() to see where the error occurred.

If I use map() instead of map_*() then I get a list-column of integer64. From what I understand, tibble/dplyr supports columns of 64-bit integers, so it would be great to know how to return them from map_*()


Solution

  • Probably easiest here is to simply pipe to unnest():

    tibble(x=1:3) %>% 
      mutate(y=map(x,~as.integer64(2^4))) %>%
      unnest(y)
    

    Output:

    # A tibble: 3 × 2
          x       y
      <int> <int64>
    1     1      16
    2     2      16
    3     3      16