The following function concatenates words of an input expression and prints them as strings:
f <- function(e) {
e <- deparse(substitute(e))
gsub(" \\+ ", "", e)
}
f(a + e)
[1] "ae"
f(ä + e)
[1] "äe"
When I place the same function definition and calls into an .rmd file, however, RStudio shows an error:
When knitting the .rmd file the output looks ok.
My complete .rmd
file:
f <- function(e) {
e <- deparse(substitute(e))
gsub(" \\+ ", "", e)
}
f(a + e)
f(ä + e)
Now my questions are:
- Why is
ä
inside an.rmd
file an unexpected token, while it is fine inside an.r
file? - Why does
knit
still work if there are unexpected tokens?
And a bit more vague:
- Is it somewhat safe to allow ä, ö & ü inside a DSL notation (that's what I'm working on in the big picture..)?
- Can I parse
.r
files for ä, ö & ü in order to throw an error from within my DSL?
The question is also placed on SO.