Escaping backslash (\) in string or paths in R

后端 未结 4 1489
名媛妹妹
名媛妹妹 2020-11-27 08:21

Windows copies path with backslash \\, which R does not accept. So, I wanted to write a function which would convert \\ to /. For exam

4条回答
  •  北海茫月
    2020-11-27 09:04

    From R 4.0.0 you can use r"(...)" to write a path as raw string constant, which avoids the need for escaping:

    r"(E:\RStuff\test.r)"
    # [1] "E:\\RStuff\\test.r"
    

    There is a new syntax for specifying raw character constants similar to the one used in C++: r"(...)" with ... any character sequence not containing the sequence )". This makes it easier to write strings that contain backslashes or both single and double quotes. For more details see ?Quotes.

提交回复
热议问题