When escaping the $
character using R's sub
function as in sub('\\$', '', '$1.99')
why is it necessary to use a double back slash?
Asked
Active
Viewed 30 times
0

dsaxton
- 995
- 2
- 10
- 23
-
1Because "\" is a metacharacter in R too, so it too needs to be escaped. – joran Mar 29 '16 at 01:21
-
1e.g http://stackoverflow.com/q/11806501/324364 or (my favorite) http://stackoverflow.com/questions/14879204/how-to-escape-a-backslash-in-r#comment20862252_14879204 – joran Mar 29 '16 at 01:24
-
Interesting, but it is escaped using the backslash itself? – dsaxton Mar 29 '16 at 01:24
-
1Yes, in R strings every two backslashes equals one. – joran Mar 29 '16 at 01:26