Skip to content

Commit

Permalink
Take the chance to talk about the glue class and printing
Browse files Browse the repository at this point in the history
  • Loading branch information
jennybc committed Aug 28, 2024
1 parent e593e1d commit 79e932d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions vignettes/glue.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,26 @@ y <- glue("
unclass(y)
```

We use `unclass()` above to make it easier to see the absence and presence of the newlines, i.e. to reveal the literal `\n` escape sequences.
`glue()` and friends generally return a glue object, which is a character vector with the S3 class `"glue"`.
The `"glue"` class exists primarily for the sake of a print method, which displays the natural formatted result of a glue string.
Most of the time this is *exactly* what the user wants to see.
The example above happens to be an exception, where we really do want to see the underlying string representation.

Here's another example to drive home the difference between printing a glue object and looking at its string representation:

```{r}
x <- glue('
abc
" }
xyz')
class(x)
x
unclass(x)
```

## Delimiters

By default, code to be evaluated goes inside `{}` in a glue string.
Expand Down

0 comments on commit 79e932d

Please sign in to comment.