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

Reply via email to