Why and where is `ä` an unexpected token in R and how should I deal with it?

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:

enter image description here

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.

2 Likes

What version of R studio are you using? I had a similar issue with non ASCII characters but is no longer present on the preview version of Rstudio, give it a try.

https://www.rstudio.com/products/rstudio/download/preview/

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.