user63230
user63230

Reputation: 4708

Printing tibble character variable appears with quotation marks

When I read in a file I couldn't work out why two similar character variables were printing differently using tibble - one with quotation marks and the other one without. After a bit of digging, I noticed that one contained trailing white space and the other one didn't.

Is white space the only reason why a character variable would be printed with quotation marks? I can't see any reference to this behaviour on the tibble site.

Example:

library(tidyverse)
df <- tibble(a = c("hjhjh", "popopo"), d = c(1, 2))
df
# # A tibble: 2 x 2
#   a          d
#   <chr>  <dbl>
# 1 hjhjh      1
# 2 popopo     2

df_with_space <- tibble(a = c("hjhjh ", "popopo"), d = c(1, 2))
df_with_space
#quotation marks:
# # A tibble: 2 x 2
#   a            d
#   <chr>    <dbl>
# 1 "hjhjh "     1
# 2 "popopo"     2

Upvotes: 3

Views: 496

Answers (1)

zx8754
zx8754

Reputation: 56259

tibble uses pillar for printing options, compare:

> pillar::pillar("abc")
<pillar>
<chr>
abc  

> pillar::pillar(" def")
<pillar>
<chr> 
" def"

As of tibble 3.1.0, printing is handled entirely by the pillar package.

Upvotes: 3

Related Questions