I believe that would require a change to R itself. If you can make do
with a workaround then
1. this works but has the drawback that you need to define your own
string class. Below fmt
is an object with class "mystring".
as.mystring <- function(x) structure(x, class = "mystring")
"!.mystring" <- glue
fmt <- as.mystring("pi = {pi}")
!fmt
## pi = 3.14159265358979
2. Another workaround if you are going to subsequently pass that
resulting string to some other
function anyways is to preface that function with fn$. It also
supports expressions surrounded
in backticks. The function does not have to be cat.
library(gsubfn)
fn$cat("pi = $pi\n")
## pi = 3.14159265358979
On Sun, Dec 14, 2025 at 8:07?PM ivo welch <ivo.welch at ucla.edu>
wrote:>
> One of the more convenient syntax sugars of perl is the embedding of
> variables in strings, aka, `$s="I am $a";`. R has similar
functionality
> through library glue. Alas, the library does not have the operator
> flexibility to make it possible for glue to introduce a `g"I am
{a}"` .
> (One can define g("I am {a}") but that steals more of the
function
> namespace.) Would be nice sugar for end users to have...
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
Le 15/12/2025 ? 16:02, Gabor Grothendieck a ?crit?:> I believe that would require a change to R itself. If you can make do > with a workaround then > > 1. this works but has the drawback that you need to define your own > string class. Below fmt > is an object with class "mystring". > > as.mystring <- function(x) structure(x, class = "mystring") > "!.mystring" <- glue > > fmt <- as.mystring("pi = {pi}") > !fmt > ## pi = 3.14159265358979Nice. Which makes me think why not to use "!" on a classical string? Before now, it was a meaningless operation so no potential conflicts should appear. # setting up `!` <- function(x) UseMethod("!") # make generic `!.default` <- base::`!` # preserve the old behavior for other classes `!.character`=glue::glue # make act as a glue on strings # usage !"pi={pi}" # pi=3.14159265358979 !FALSE # [1] TRUE ## as before Best, Serguei.> > 2. Another workaround if you are going to subsequently pass that > resulting string to some other > function anyways is to preface that function with fn$. It also > supports expressions surrounded > in backticks. The function does not have to be cat. > > library(gsubfn) > fn$cat("pi = $pi\n") > ## pi = 3.14159265358979 > > On Sun, Dec 14, 2025 at 8:07?PM ivo welch <ivo.welch at ucla.edu> wrote: >> One of the more convenient syntax sugars of perl is the embedding of >> variables in strings, aka, `$s="I am $a";`. R has similar functionality >> through library glue. Alas, the library does not have the operator >> flexibility to make it possible for glue to introduce a `g"I am {a}"` . >> (One can define g("I am {a}") but that steals more of the function >> namespace.) Would be nice sugar for end users to have... >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-devel at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-devel > >-- Serguei Sokol Ingenieur de recherche INRAE Cellule Math?matiques TBI, INSA/INRAE UMR 792, INSA/CNRS UMR 5504 135 Avenue de Rangueil 31077 Toulouse Cedex 04 tel: +33 5 61 55 98 49 email: sokol at insa-toulouse.fr https://www.toulouse-biotechnology-institute.fr/en/plateformes-plateaux/cellule-mathematiques/
interesting. thank you, G. if the R change is not difficult, then
perhaps it's still worth it. it would require R understanding glue
interpolation, however, but this would presumably be isolated to the
definition of g"...", and not require other intervention.
it may also indirectly encourage better error messages.
```
stop( g"the input {x} is too small" )
stopifnot( x > 2, msg= g" (x=$x)" )
```
--
Ivo Welch (ivo.welch at ucla.edu)
http://www.ivo-welch.info/
J. Fred Weston Distinguished Professor, UCLA Anderson
On Mon, Dec 15, 2025 at 7:02?AM Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:>
> I believe that would require a change to R itself. If you can make do
> with a workaround then
>
> 1. this works but has the drawback that you need to define your own
> string class. Below fmt
> is an object with class "mystring".
>
> as.mystring <- function(x) structure(x, class = "mystring")
> "!.mystring" <- glue
>
> fmt <- as.mystring("pi = {pi}")
> !fmt
> ## pi = 3.14159265358979
>
> 2. Another workaround if you are going to subsequently pass that
> resulting string to some other
> function anyways is to preface that function with fn$. It also
> supports expressions surrounded
> in backticks. The function does not have to be cat.
>
> library(gsubfn)
> fn$cat("pi = $pi\n")
> ## pi = 3.14159265358979
>
> On Sun, Dec 14, 2025 at 8:07?PM ivo welch <ivo.welch at ucla.edu>
wrote:
> >
> > One of the more convenient syntax sugars of perl is the embedding of
> > variables in strings, aka, `$s="I am $a";`. R has similar
functionality
> > through library glue. Alas, the library does not have the operator
> > flexibility to make it possible for glue to introduce a `g"I am
{a}"` .
> > (One can define g("I am {a}") but that steals more of the
function
> > namespace.) Would be nice sugar for end users to have...
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-devel at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
>
>
>
> --
> Statistics & Software Consulting
> GKX Group, GKX Associates Inc.
> tel: 1-877-GKX-GROUP
> email: ggrothendieck at gmail.com