Skip to content

Tibble doesn't recycle difftimes properly. #284

Closed
@ghost

Description

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviorcategory:interface

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions