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

Escaping Backticks in String Interpolation in gsubfn #1

Open
brodieG opened this issue Dec 20, 2016 · 1 comment
Open

Escaping Backticks in String Interpolation in gsubfn #1

brodieG opened this issue Dec 20, 2016 · 1 comment

Comments

@brodieG
Copy link

brodieG commented Dec 20, 2016

a <- 10
b <- 5

fn$c("Hello $a + $b should equal `a + b`, but `don't evalute me`, $b")

I would want to be able to escape the second pair of backticks, or dollar signs e.g.:

fn$c("Hello $a + $b should equal `a + b`, but ``don't evalute me``, $$b")
## "Hello 10 + 5 should equal 15, but `don't evalute me`"

I think this can be achieved by changing pattern in:

if (missing(pattern)) pattern <- "[$]([[:alpha:]][[:alnum:].]*)|`([^`]+)`"

To something like (with perl=T):

"(?<!\\$)[$]([[:alpha:]][[:alnum:].]*)|`(?<!`)`([^`]+)`(?!`)`"

This type of escaping is probably simpler than anything involving backslashes given those have special meaning within R and with regexes as well. The only unfortunate thing is this is different to how the formula escaping works, where ~~ is the function.

Additionally, one complication is that we need to make sure that things like:

``don't evaluate me``

are not only not evaluated, but also converted to

`don't evaluate me`
@brodieG
Copy link
Author

brodieG commented Dec 21, 2016

Also need to consider potential conflicts with knitr and the triple backtick (as per @ggrothendieck)

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

1 participant