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 ([email protected])
http://www.ivo-welch.info/
J. Fred Weston Distinguished Professor, UCLA Anderson
On Mon, Dec 15, 2025 at 7:02 AM Gabor Grothendieck
<[email protected]> 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 <[email protected]> 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]]
> >
> > ______________________________________________
> > [email protected] 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
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel