Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tibble doesn't recycle difftimes properly. #284

Closed
ghost opened this issue Jul 28, 2017 · 2 comments · Fixed by #298
Closed

Tibble doesn't recycle difftimes properly. #284

ghost opened this issue Jul 28, 2017 · 2 comments · Fixed by #298
Labels
bug an unexpected problem or unintended behavior category:interface

Comments

@ghost
Copy link

ghost commented Jul 28, 2017

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.

@krlmlr
Copy link
Member

krlmlr commented Jul 28, 2017

Thanks. AFAIK, tibbles recycle only length-1 vectors.

@krlmlr krlmlr added bug an unexpected problem or unintended behavior category:interface labels Jul 28, 2017
krlmlr added a commit that referenced this issue Aug 19, 2017
- Values of length 1 in a `tibble()` call are recycled prior to evaluating subsequent arguments, improving consistency with `mutate()` (#213).
- Recycling of values of length 1 in a `tibble()` call maintains their class (#284).
krlmlr added a commit that referenced this issue Aug 22, 2017
Bug fixes
---------

- Values of length 1 in a `tibble()` call are recycled prior to evaluating subsequent arguments, improving consistency with `mutate()` (#213).
- Recycling of values of length 1 in a `tibble()` call maintains their class (#284).
- `add_row()` now always preserves the column data types of the input data frame the same way as `rbind()` does (#296).
- `lst()` now again handles duplicate names, the value defined last is used in case of a clash.
- Adding columns to zero-row data frames now also works when mixing lengths 1 and 0 in the new columns (#167).
- The `validate` argument is now also supported in `as_tibble.tbl_df()`, with default to `FALSE` (#278).  It must be passed as named argument, as in `as_tibble(validate = TRUE)`.

Formatting
----------

- `format_v()` now always surrounds lists with `[]` brackets, even if their length is one. This affects `glimpse()` output for list columns (#106).
- Factor levels are escaped when printing (#277).
- Non-syntactic names are now also escaped in `glimpse()` (#280).
- `tibble()` gives a consistent error message in the case of duplicate column names (#291).
@github-actions
Copy link
Contributor

github-actions bot commented Jun 2, 2021

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior category:interface
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant