Skip to content

Verify that print shows values from the added column in epi_slide examples #83

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

Closed
dajmcdon opened this issue May 24, 2022 · 1 comment · Fixed by #130
Closed

Verify that print shows values from the added column in epi_slide examples #83

dajmcdon opened this issue May 24, 2022 · 1 comment · Fixed by #130
Assignees
Labels
P1 medium priority REPL Improved print, errors, etc.

Comments

@dajmcdon
Copy link
Contributor

Seems like it's system or version dependent. Maybe because I have

> getOption("width")
[1] 80

? Or maybe it's a version thing (I am on tibble_3.1.7, R version 4.0.5 (2021-03-31)).

You can probably recreate what I'm seeing with withr::with_options(list(width=80L), print(a)).

Experiments:
> 
> print(a)
An `epi_df` object, with metadata:
* geo_type  = state
* time_type = day
* as_of     = 2022-05-20 11:39:30

# A tibble: 60 × 7
# Groups:   geo_value [4]
   geo_value time_value case_rate_7d_av death_rate_7d_av cases cases_7d_av
 * <chr>     <date>               <dbl>            <dbl> <dbl>       <dbl>
 1 ca        2020-06-01            6.85            0.161  2439       2695.
 2 ca        2020-06-02            6.83            0.184  2421       2688.
 3 ca        2020-06-03            6.67            0.172  2221       2624.
 4 ca        2020-06-04            6.98            0.168  3030       2749.
 5 ca        2020-06-05            6.98            0.166  3130       2747 
 6 ca        2020-06-06            6.67            0.169  2807       2626.
 7 ca        2020-06-07            6.74            0.165  2022       2655.
 8 ca        2020-06-08            6.68            0.159  2254       2628.
 9 ca        2020-06-09            6.82            0.161  2812       2684.
10 ca        2020-06-10            7.14            0.175  3100       2810.
# … with 50 more rows, and 1 more variable: cases_7dav <dbl>
> print(a, width=200L)
An `epi_df` object, with metadata:
* geo_type  = state
* time_type = day
* as_of     = 2022-05-20 11:39:30

# A tibble: 60 × 7
# Groups:   geo_value [4]
   geo_value time_value case_rate_7d_av death_rate_7d_av cases cases_7d_av
 * <chr>     <date>               <dbl>            <dbl> <dbl>       <dbl>
 1 ca        2020-06-01            6.85            0.161  2439       2695.
 2 ca        2020-06-02            6.83            0.184  2421       2688.
 3 ca        2020-06-03            6.67            0.172  2221       2624.
 4 ca        2020-06-04            6.98            0.168  3030       2749.
 5 ca        2020-06-05            6.98            0.166  3130       2747 
 6 ca        2020-06-06            6.67            0.169  2807       2626.
 7 ca        2020-06-07            6.74            0.165  2022       2655.
 8 ca        2020-06-08            6.68            0.159  2254       2628.
 9 ca        2020-06-09            6.82            0.161  2812       2684.
10 ca        2020-06-10            7.14            0.175  3100       2810.
   cases_7dav
 *      <dbl>
 1      2581.
 2      2555 
 3      2611.
 4      2736.
 5      2734.
 6      2830 
 7      2909.
 8      2946 
 9      2955.
10      2979.
# … with 50 more rows
> withr::with_options(list(width=200L), print(a))
An `epi_df` object, with metadata:
* geo_type  = state
* time_type = day
* as_of     = 2022-05-20 11:39:30

# A tibble: 60 × 7
# Groups:   geo_value [4]
   geo_value time_value case_rate_7d_av death_rate_7d_av cases cases_7d_av cases_7dav
 * <chr>     <date>               <dbl>            <dbl> <dbl>       <dbl>      <dbl>
 1 ca        2020-06-01            6.85            0.161  2439       2695.      2581.
 2 ca        2020-06-02            6.83            0.184  2421       2688.      2555 
 3 ca        2020-06-03            6.67            0.172  2221       2624.      2611.
 4 ca        2020-06-04            6.98            0.168  3030       2749.      2736.
 5 ca        2020-06-05            6.98            0.166  3130       2747       2734.
 6 ca        2020-06-06            6.67            0.169  2807       2626.      2830 
 7 ca        2020-06-07            6.74            0.165  2022       2655.      2909.
 8 ca        2020-06-08            6.68            0.159  2254       2628.      2946 
 9 ca        2020-06-09            6.82            0.161  2812       2684.      2955.
10 ca        2020-06-10            7.14            0.175  3100       2810.      2979.
# … with 50 more rows

Originally posted by @brookslogan in #77 (comment)

@brookslogan brookslogan added P1 medium priority REPL Improved print, errors, etc. labels May 24, 2022
@brookslogan brookslogan changed the title Verify that print for epi_slide shows values from the added column Verify that print shows values from the added column in epi_slide examples Jun 2, 2022
@rachlobay
Copy link
Collaborator

rachlobay commented Jun 16, 2022

I had a quick look at this yesterday and it may be the long column names are causing the issue... When we consider the sum of the characters for the column names and the whitespaces, the line with the column names surpasses the default of ~80 characters per line (there are 85 characters printed in the console for the column names line in the first epi_slide ex.).

We can look at that first epi_slide example to see this better:

library(epiprocess)
c <- b <- a <- jhu_csse_daily_subset %>%
  group_by(geo_value) %>%
  epi_slide(cases_7dav = mean(cases), n = 7, 
            align = "right")
colnames(a)
# sum(nchar(colnames(a))) + num of whitespaces in-between colnames + 3 whitespaces at beginning (before geo_value)
sum(nchar(colnames(a))) + 6 + 3 

So, the key takeaway here is that the sum of the characters on that line is 85.

When we use any width of 85 or above, all of the columns are printed as intended.

withr::with_options(list(width=85L), print(a))
withr::with_options(list(width=129L), print(a))

Or when we reduce the number of characters in the column names so that the total printed in that line (when whitespaces are included) <= 80, then it also works.

names(b) = 1:7
b

colnames(c)[4] = "death_7d_av"
withr::with_options(list(width=85L), print(c))

So, if you really want the added column to be printed, one solution is to shorten 1+ of the column names to ensure that the default width of 80 is not surpassed.

@brookslogan what do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 medium priority REPL Improved print, errors, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants