1

dplyr::lag works fine with integers with the first entry being <NA>, but with bit64::integer64 the first entry is a huge number.

This is my setting:

library(tidyverse)
library(magrittr)
#> ...
library(bit64)
#> Loading required package: bit
#> Attaching package bit
#> ...
#> Attaching package bit64
#> ...
#> The following object is masked from 'package:bit':
#> 
#>     still.identical
#> The following objects are masked from 'package:base':
#> 
#>     :, %in%, is.double, match, order, rank
library(reprex)
sessionInfo()
#> R version 3.6.1 (2019-07-05)
#> Platform: x86_64-apple-darwin18.6.0 (64-bit)
#> Running under: macOS Mojave 10.14.6
#> 
#> ...     
#> 
#> other attached packages:
#>  [1] reprex_0.3.0    bit64_0.9-7     bit_1.1-14      magrittr_1.5   
#>  [5] forcats_0.4.0   stringr_1.4.0   dplyr_0.8.1     purrr_0.3.2    
#>  [9] readr_1.3.1     tidyr_0.8.3     tibble_2.1.3    ggplot2_3.2.0  
#> [13] tidyverse_1.2.1
#> 
#> ...

Here is a minimal reprex:

tib_int64 <- tibble(A_int   = as.integer(c(1,2,3)),
                    A_int64 = as.integer64(c(1,2,3)))

tib_int64 %>% mutate(B = lag(A_int), C = lag(A_int64))
#> # A tibble: 3 x 4
#>   A_int A_int64     B C                  
#>   <int> <int64> <int> <int64>            
#> 1     1 1          NA 9218868437227407266
#> 2     2 2           1                   1
#> 3     3 3           2                   2

The first entry in the C column should be <NA> like in the B column.
Is this a dplyr problem or a bit64 problem? This is not too difficult to work around, but shouldn't this be filed as a bug?

Habert
  • 347
  • 2
  • 10
  • 2
    What happens if you set the argument `default = NA_integer64_`? – mikeck Sep 07 '19 at 02:08
  • @mikeck Thanks, that solves it nicely. The question is still should this be considered a bug? – Habert Sep 07 '19 at 03:51
  • 1
    yeah I think it's worth posting an issue on their GitHub page, seems like it should be an easy fix. – mikeck Sep 07 '19 at 04:18
  • 1
    @mikeck Thanks. Bug reported and taken care of in [tidyverse/dplyr](https://github.com/tidyverse/dplyr/issues/4558) – Habert Oct 01 '19 at 23:15

0 Answers0