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

Add pillar printing for the labelled class #340

Closed
gergness opened this issue Jan 18, 2018 · 5 comments
Closed

Add pillar printing for the labelled class #340

gergness opened this issue Jan 18, 2018 · 5 comments

Comments

@gergness
Copy link
Contributor

@gergness 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
Copy link
Member

@hadley 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
Copy link

@elbersb 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
Copy link
Contributor Author

@gergness 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
Copy link

@elbersb elbersb commented Sep 8, 2018

The PR looks great!

@hadley hadley closed this in 8489a48 Feb 1, 2019
@lock
Copy link

@lock lock bot commented Jul 31, 2019

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Jul 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants