Why does nchar("\\")=1, nchar("\abcde")=5 etc. in R ? Which function use to have nchar("\\")=2, nchar("\abcde")=6 ?
Why does nchar(\\)=1, nchar(\abcde)=5 etc. in R ? Which function use to have nchar(\\)=2,
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In R, if you want a literal
\, you need to escape it as other’s have said. I don’t see the reason forencodeString()in your examples. It is easier to just usenchar()and remember the first line of my Answer: escape your\If you want to forget about the escape then
encodeString()can help, but you either do one (escape them manually) or useescapeString(), not both:Finally,
\uXXXXis a way of entering a unicode characters in R and this catches outencodeString():as it wants to treat this as a representation of a unicode character. In this case, the “escape them yourself” thing does the right thing:
I’m not sure of a straight forward way to replace
\with\\in R where the string is a\uXXXXas that will get interpreted first to the unicdoe character and only then will the replacement take place (but at that point there are no\. See?Quotesfor a list of the escape sequences used in R.