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

Add pillar printing for the labelled class #340

Open
gergness opened this Issue Jan 18, 2018 · 4 comments

Comments

Projects
None yet
3 participants
@gergness
Copy link
Contributor

gergness commented Jan 18, 2018

I think the labelled class would benefit from having a print method from the pillar package. For labelled values it would be nice to show the label with subtle styling and the special NA values could also be marked as well.

If you're interested, I'm happy to make a first attempt in a PR.

@hadley

This comment has been minimized.

Copy link
Member

hadley commented Feb 15, 2018

Sure, sounds great!

gergness added a commit to gergness/haven that referenced this issue Feb 18, 2018

gergness added a commit to gergness/haven that referenced this issue Jun 27, 2018

@elbersb

This comment has been minimized.

Copy link

elbersb commented Sep 4, 2018

Would this also fix this strange printing issue that occurs now when printing a tibble with a labelled column? See below for an example, where the 1 is surrounded by quotes. This only seems to happen when the numbers have different numbers of digits (see second example).

d <- tibble::tibble(s = haven::labelled(c(1, 10), labels = c("A" = 1, "B" = 10)))
d
#> # A tibble: 2 x 1
#>   s        
#>   <dbl+lbl>
#> 1 " 1"     
#> 2 10
d <- tibble::tibble(s = haven::labelled(c(1, 2), labels = c("A" = 1, "B" = 2)))
d
#> # A tibble: 2 x 1
#>   s        
#>   <dbl+lbl>
#> 1 1        
#> 2 2

Created on 2018-09-04 by the reprex
package
(v0.2.0).

@gergness

This comment has been minimized.

Copy link
Contributor

gergness commented Sep 8, 2018

Oh yeah, agree that this should be fixed. I don't think the design is final yet, but the current implementation in #390 has pretty good behavior.

d <- tibble::tibble(s = haven::labelled(c(1, 10), labels = c("A" = 1, "B" = 10)))
d
#> # A tibble: 2 x 1
#>   s        
#>   <dbl+lbl>
#> 1  1 [A]   
#> 2 10 [B]


# Can also get just the values with correct spacing by setting option
options("haven.show_pillar_labels" = FALSE)
d
#> # A tibble: 2 x 1
#>           s
#>   <dbl+lbl>
#> 1         1
#> 2        10

Created on 2018-09-08 by the reprex package (v0.2.0).

@elbersb

This comment has been minimized.

Copy link

elbersb commented Sep 8, 2018

The PR looks great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment