Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7837697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:48:25+00:00 2026-06-02T14:48:25+00:00

Why does nchar(\\)=1, nchar(\abcde)=5 etc. in R ? Which function use to have nchar(\\)=2,

  • 0

Why does nchar("\\")=1, nchar("\abcde")=5 etc. in R ? Which function use to have nchar("\\")=2, nchar("\abcde")=6 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T14:48:27+00:00Added an answer on June 2, 2026 at 2:48 pm

    In R, if you want a literal \, you need to escape it as other’s have said. I don’t see the reason for encodeString() in your examples. It is easier to just use nchar() and remember the first line of my Answer: escape your \

    > nchar("\\\\")
    [1] 2
    > nchar("\\abcde")
    [1] 6
    

    If you want to forget about the escape then encodeString() can help, but you either do one (escape them manually) or use escapeString(), not both:

    > encodeString("\\")
    [1] "\\\\"
    > encodeString("\abcde")
    [1] "\\abcde"
    

    Finally, \uXXXX is a way of entering a unicode characters in R and this catches out encodeString():

    > nchar(encodeString("\u2642"))
    [1] 1
    

    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:

    > nchar("\\u2642")
    [1] 6
    

    I’m not sure of a straight forward way to replace \ with \\ in R where the string is a \uXXXX as 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 ?Quotes for a list of the escape sequences used in R.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a global javascript function which .appends() a tooltip element to any element
Does Blend have anything similar to the MsBuild BuildingInsideVisualStudio variable, which is set by
I'm aware that Oracle does not have a boolean type to use for parameters,
Does anyone have a nice solution for GalleryView when I want to display photos
Does anyone have any idea how to change the thickness of the text pointer
Does anyone have some code that will take a TimeZoneInfo field from .NET and
Does any one have a solution to make the SpecFlow autocomplete in Visual Studio
I have a table which fills out the rows I have put in there
Does anyone have any suggestions for the best / simplest way to view all
Does OpenJPA have any support for batch insert similar to Hibernate ? I haven't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.