Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When evaluating a braced paste() expression that returns a single string, glue() incorporates text outside the braces #344

Closed
homerhanumat opened this issue Dec 9, 2024 · 2 comments

Comments

@homerhanumat
Copy link

This

library(glue)
vowels <- c("a", "e", "i", "o", "u")
glue("The vowels are: {paste(vowels, collapse = ", ")}.")

produces:

The vowels are: a.
The vowels are: e.
The vowels are: i.
The vowels are: o.
The vowels are: u.

One expects the output to be the same as:

library(glue)
vowels <- c("a", "e", "i", "o", "u")
vowels_pasted <- paste(vowels, collapse = ", ")
glue("The vowels are: {vowels_pasted}.")
The vowels are: a, e, i, o, u.

Session info:

R version 4.4.2 (2024-10-31)
Platform: aarch64-apple-darwin20
Running under: macOS Sequoia 15.1.1

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/New_York
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] glue_1.8.0

loaded via a namespace (and not attached):
[1] compiler_4.4.2    cli_3.6.3         tools_4.4.2       rstudioapi_0.17.0
[5] crayon_1.5.3      rlang_1.1.4     
@remlapmot
Copy link

I'd guess this is simply because you've used double quotes twice.

Switching one of the double quotes to single quotes gives the expected output.

library(glue)
vowels <- c("a", "e", "i", "o", "u")
glue("The vowels are: {paste(vowels, collapse = ', ')}.")
#> The vowels are: a, e, i, o, u.

Created on 2024-12-09 with reprex v2.1.1

@homerhanumat
Copy link
Author

That's right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants