"\ w" is an unrecognized escape "in grep

I use grep on some projects in R (which uses the perl=TRUE flag), and for a living I can’t understand why R keeps throwing errors. My request is as follows:

 d$SomeColumn[grep("(?ix)<VNW[^;]*;(dis|dat)> \w*<N\(", d$Right, perl=TRUE)] <- 1 

However, R raises the following error:

 Error: '\w' is an unrecognized escape in character string starting ""<VNW[^;]*;(dis|dat)> \w" 
+6
source share
1 answer

You need to avoid backslashes in r again.

 d$SomeColumn[grep("(?ix)<VNW[^;]*;(dis|dat)> \\w*<N\\(", d$Right, perl=TRUE)] <- 1 | | 
+11
source

Source: https://habr.com/ru/post/979791/


All Articles