Skip to content

Commit

Permalink
Use function body example here too; rebuild README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jennybc committed Aug 28, 2024
1 parent ec56c22 commit b078e9b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
10 changes: 6 additions & 4 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,20 @@ There is considerably less syntactical noise and mystery compared to `paste()` a

Empty first and last lines are automatically trimmed, as is leading whitespace that is common across all lines.
You don't have to choose between indenting your code properly and getting the output you actually want.
Consider what happens when `glue()` is used inside the body of a function:

```{r}
if (TRUE) {
foo <- function() {
glue("
A formatted string
Can have multiple lines
with additional indention preserved
"
)
with additional indention preserved")
}
foo()
```

The leading whitespace that is common to all 3 lines is absent from the result.

## Learning more

glue is a relatively small and focused package, but there's more to it than the basic usage of `glue()` and `glue_data()` shown here.
Expand Down
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ str_glue("My name is {name}.")
#> My name is Wilma.
```

You’re not limited to using a bare symbol inside `{}`; it can basically
be any little bit of R code:
You’re not limited to using a bare symbol inside `{}`; it can be any
little bit of R code:

``` r
name <- "Pebbles"
Expand Down Expand Up @@ -116,35 +116,38 @@ vectorized over the data.

`glue()` lets you write code that makes it easy to predict what the
final string will look like. There is considerably less syntactical
noise and mystery, compared to `paste()` and `sprintf()`, for example.
noise and mystery compared to `paste()` and `sprintf()`.

Empty first and last lines are automatically trimmed, as is leading
whitespace that is common across all lines. You don’t have to choose
between indenting your code properly and getting the output you actually
want.
want. Consider what happens when `glue()` is used inside the body of a
function:

``` r
if (TRUE) {
foo <- function() {
glue("
A formatted string
Can have multiple lines
with additional indention preserved
"
)
with additional indention preserved")
}
foo()
#> A formatted string
#> Can have multiple lines
#> with additional indention preserved
```

The leading whitespace that is common to all 3 lines is absent from the
result.

## Learning more

glue is a relatively small and focused package, but there’s more to it
than the basic usage of `glue()` and `glue_data()` shown here. More
recommended functions and resources:

- The “Get started” article (`vignette("glue", package = "glue")`)
demonstrates more interesting features of `glue()` and `glue_data()`.
- The “Get started” article (`vignette("glue")`) demonstrates more
interesting features of `glue()` and `glue_data()`.
- `glue_sql()` and `glue_data_sql()` are specialized functions for
producing SQL statements.
- glue provides a couple of custom knitr engines that allow you to use
Expand Down

0 comments on commit b078e9b

Please sign in to comment.