documentation for tibble/pillar quoting of 'hidden' spaces in character variables

Hi,
For teaching purposes, I'm trying to track down any explicit documentation about how tibble/pillar/colformat makes strings with leading or trailing spaces evident through quotes. I love the feature, btw.

I found this issue by Noam Ross, but so far nothing in the documentation or vignettes about how or why this was incorporated.

Any leads?
thanks!

its implemented through pillar_shaft.character method

function (x, ..., min_width = NULL) 
{
  x <- utf8::utf8_encode(x)
  out <- x
  needs_quotes <- which(is_ambiguous_string(x))
  if (has_length(needs_quotes)) {
    out[needs_quotes] <- gsub("\"", "\\\"", x[needs_quotes], 
      fixed = TRUE)
    out[!is.na(x)] <- paste0(style_subtle("\""), out[!is.na(x)], 
      style_subtle("\""))
    na_indent <- 1
  }

etc...

I suppose you may be enquiring mostly about pillar:::is_ambiguous_string

function (x) 
{
    !is.na(x) & grepl("^$|^ | $|\\\\|\"", x)
}
1 Like

thanks!
This is exactly what I was looking for.

Do you know if this is stated explicitly in a function's help, or if 'ambiguous strings' are defined somewhere?
(defined verbally and not just through a regexp)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.