Look at the gsubfn package, it has functionality to do this.
Here is an example from the vignette:
> fn$cat("pi = $pi, exp = `exp(1)`\n")
pi = 3.14159265358979, exp = 2.71828182845905
The formula syntax to function conversion in the package may help with the
last part.
On Fri, Feb 8, 2013 at 5:01 PM, ivo welch <[email protected]>wrote:
> dear R experts---I am trying to replicate a perl feature. I want to be
> able to embed R commands inside a character string, and have the
> string be printed with the command executed. my perl equivalent is
>
> my $a=10;
> my $teststring = "the expression, $a+1, is ::$a+1::, but add one
> more for ::$a+2::\n";
> $teststring =~ s/::(.*?)::/$1/gee;
> print $teststring;
>
> of course, R does not use '$' for variable names. my ultimate goal is
> to write something like
>
> cat("d is a ::class(d):: with names ::names(d)::")
>
> of course, I know I can write this as cat("d is a", class(d), "with
> names", names(d)), but I also want to be define %or% so that I can
> write
>
> (is.data.frame(d)) %or% "d is a ::class(d):: with names ::names(d)::" ;
>
> operators don't take variable arguments afaik. :-(.
>
> advice appreciated.
>
> regards,
>
> /iaw
> ----
> Ivo Welch ([email protected])
>
> ______________________________________________
> [email protected] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Gregory (Greg) L. Snow Ph.D.
[email protected]
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.