lubridate icon indicating copy to clipboard operation
lubridate copied to clipboard

period error inside mutate

Open JulioV opened this issue 4 years ago • 0 comments

There's an error, similar to this issue, that happens when using period inside mutate and both num and units are columns in the tibble being piped. This happens regardless of whether or not my_units has the same or different values.

 tibble(time = c("13","12"), my_units = c("days", "days")) %>% mutate(hm = lubridate::period(num=as.integer(time), units=my_units))

Expected output:

  time  my_units hm          
  <chr> <chr>    <Period>    
1 13    days     13d 0H 0M 0S
2 12    days     12d 0H 0M 0S 

Actual output

  time  my_units hm          
  <chr> <chr>    <Period>    
1 13    days     25d 0H 0M 0S
2 12    days     NA 

When units are fixed, the error is different:

> tibble(time = c("13","12"), my_units = c("days", "seconds")) %>%
+     mutate(hm = lubridate::period(num=as.integer(time), units="seconds"))
Error in .period_from_num(num, units) : 
  Arguments `num` and `units` must have same length
"Package": "vctrs",
"Version": "0.3.0",
"Package": "lubridate",
"Version": "1.7.8",
"Package": "tidyr",
"Version": "1.1.0",

JulioV avatar Aug 21 '20 20:08 JulioV