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 creation not inputting (or displaying) correct values #1568

Open
hathawayj opened this issue Jan 19, 2024 · 2 comments
Open

Tibble creation not inputting (or displaying) correct values #1568

hathawayj opened this issue Jan 19, 2024 · 2 comments

Comments

@hathawayj
Copy link

The tibble creation changes the stats_time variable display to look like it goes through 2008. However, when the values are pulled it looks like they are the input values...

library(tibble)
library(dplyr)
new_t <-  seq(2006, len = 2 * 12, by = 1/12)

tibble(
    stats_time = new_t,
    month = rep(1:12, 2)
    ) |> print(n = 24)

data.frame(
    stats_time = new_t,
    month = rep(1:12, 2)
)

tibble(
    stats_time = new_t,
    month = rep(1:12, 2)
    ) |> pull(stats_time)
@krlmlr
Copy link
Member

krlmlr commented Jan 20, 2024

Thanks. This is documented in https://tibble.tidyverse.org/articles/digits.html#trailing-dot . One could argue that there should always be at least one digit after the terminal dot, just to avoid this sort of confusion.

The reprex package is preferred for sharing examples, would have saved me some time to see the core of the problem. It's very easy to use and gives both the requester and the supporter an advantage:

library(tibble)

new_t <- seq(2006, len = 2 * 12, by = 1 / 12)
new_t[17:20]
#> [1] 2007.333 2007.417 2007.500 2007.583

df <- data.frame(
  stats_time = new_t,
  month = rep(1:12, 2)
)

df[17:20, ]
#>    stats_time month
#> 17   2007.333     5
#> 18   2007.417     6
#> 19   2007.500     7
#> 20   2007.583     8
as_tibble(df)[17:20, ]
#> # A tibble: 4 × 2
#>   stats_time month
#>        <dbl> <int>
#> 1      2007.     5
#> 2      2007.     6
#> 3      2008.     7
#> 4      2008.     8

Created on 2024-01-20 with reprex v2.0.2

@hathawayj
Copy link
Author

Thanks. I worry about rounding it to a different number. I could see clipping it. Sorry about the reprex(). I appreciate that your responded without it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants