Ignore escape characters (backslashes) in R strings

As of version 4.0, introduced in April 2020, R provides a syntax for specifying raw strings. The string in the example can be written as:

path <- r"(C:\Users\mhermans\somefile.csv)"

From ?Quotes:

Raw character constants are also available using a syntax similar to the one used in C++: r"(...)" with ... any character sequence, except that it must not contain the closing sequence )". The delimiter pairs [] and {} can also be used, and R can be used in place of r. For additional flexibility, a number of dashes can be placed between the opening quote and the opening delimiter, as long as the same number of dashes appear between the closing delimiter and the closing quote.


You can try to use the 'allowEscapes' argument in scan()

X=scan(what="character",allowEscapes=F)
C:\Users\mhermans\somefile.csv

print(X)
[1] "C:\\Users\\mhermans\\somefile.csv"