MilesMcBain / datapasta

On top of spaghetti, all covered in cheese....
https://milesmcbain.github.io/datapasta/
Other
891 stars 58 forks source link

error in tribble_construct #120

Closed mgacc0 closed 3 years ago

mgacc0 commented 3 years ago
if (!require("pacman")) install.packages("pacman")
pacman::p_load(tidyverse, lubridate, datapasta)

d <- data.frame(
  individual = c(rep("A", 1), rep("B", 2), rep("C", 5)),
  date = as_date(c(
    rep("2020-02-01", 1),
    rep("2020-03-02", 2),
    rep("2020-04-01", 5)
  )),
  test = c(NA, 0, 1, 1, 1, 0, 0, 0),
  date_test = c(
    NA,
    as_date("2020-03-04"),
    as_date("2020-04-01"),
    seq(as_date("2020-01-01"), as_date("2020-06-01"), length.out = 5)
  ),
  x = c(1.1, rep(2.1, 2), rep(4, 5))
) %>%
  as_tibble()
d
#> # A tibble: 8 x 5
#>   individual date        test date_test     x
#>   <chr>      <date>     <dbl>     <dbl> <dbl>
#> 1 A          2020-02-01    NA        NA   1.1
#> 2 B          2020-03-02     0     18325   2.1
#> 3 B          2020-03-02     1     18353   2.1
#> 4 C          2020-04-01     1     18262   4  
#> 5 C          2020-04-01     1     18300   4  
#> 6 C          2020-04-01     0     18338   4  
#> 7 C          2020-04-01     0     18376   4  
#> 8 C          2020-04-01     0     18414   4
datapasta::dpasta(d)
#> Error in strrep(" ", char_length - nchar(char_vec)): invalid 'times' value
mgacc0 commented 3 years ago
library(tidyverse)
tibble::tribble(
  ~id, ~date,
  "A", "2020-01-01",
  "B", NA_character_
) %>%
  mutate(date = ymd(date)) %>% 
  datapasta::dpasta()
#> Error in strrep(" ", char_length - nchar(char_vec)): invalid 'times' value

It happens in tribble_construct when a column has Date type.

MilesMcBain commented 3 years ago

Thanks for reporting this. This felt a bit familiar. I am pretty sure I have already fixed this in the github and r-universe version (3.1.1) though.

Does that fix it for you also?

mgacc0 commented 3 years ago

I can confirm that it's fixed on the latest version (3.1.1) from github. Thanks.