Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing tibble character variable appears with quotation marks

Tags:

r

tibble

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
like image 768
user63230 Avatar asked Dec 17 '25 14:12

user63230


1 Answers

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.

like image 156
zx8754 Avatar answered Dec 20 '25 07:12

zx8754



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!