StackOverflow link: https://stackoverflow.com/questions/44742206/tibble-silently-changes-recycled-difftime-variables
If a difftime variable is included in a tibble, and the specified number of observations is equal to the other variable(s), then the class of the variable is maintained.
tibble::tibble(a = c(1,2), b = as.difftime(c(1,2), units = "hours"))
# A tibble: 2 x 2
a b
<dbl> <time>
1 1 1 hours
2 2 1 hours
However, if the specified number of observations in the difftime variable is a proper factor of the number of observations in the other variable, so that the difftime variable is recycled, then the class of the variable silently changes to numeric:
tibble::tibble(a = c(1,2), b = as.difftime(1, units = "hours"))
# A tibble: 2 x 2
a b
<dbl> <dbl>
1 1 1
2 2 1
From the StackOverflow link, this may be occurring because tibble::tibble uses as.vector if recycling is necessary, which strips the attributes of the vector.
StackOverflow link: https://stackoverflow.com/questions/44742206/tibble-silently-changes-recycled-difftime-variables
If a
difftimevariable is included in a tibble, and the specified number of observations is equal to the other variable(s), then the class of the variable is maintained.However, if the specified number of observations in the
difftimevariable is a proper factor of the number of observations in the other variable, so that thedifftimevariable is recycled, then the class of the variable silently changes tonumeric:From the StackOverflow link, this may be occurring because
tibble::tibbleuses as.vector if recycling is necessary, which strips the attributes of the vector.