我需要结合非标准评估使用正则表达式。
以下工作正常:
library(stringr)
> str_replace("2.5", "\\.", ",") # without non-standard evaluation
[1] "2,5"
> eval(parse(text = 'str_replace("2.5", ".", ",")')) # with non-standard evaluation
[1] ",.5"
以下不起作用:
> eval(parse(text = 'str_replace("2.5", "\\.", ",")'))
Error: '\.' is an unrecognized escape in character string starting ""\."
我在想我需要转义反斜杠本身,但是,这似乎也不起作用:
> eval(parse(text = 'str_replace("2.5", "\\\.", ",")'))
Error: '\.' is an unrecognized escape in character string starting "'str_replace("2.5", "\\\."