Bug 16091 - nchar does not compute number of human-readable characters
Summary: nchar does not compute number of human-readable characters
Status: NEW
Alias: None
Product: R
Classification: Unclassified
Component: Documentation (show other bugs)
Version: R 3.1.2
Hardware: Other Linux
: P5 enhancement
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2014-11-28 10:09 UTC by Mark van der Loo
Modified: 2014-11-28 10:09 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mark van der Loo 2014-11-28 10:09:48 UTC
Also see the thread [1] in the R-devel mailing list.

Including non-printable characters (including the zero-width nonbreaking space) does _not_ return the number of human-readable characters as stated in the documentation.

> x <- "f\ufeffoo"
> x
[1] "foo"
> nchar(x)
[1] 4

I suggest to replace in ?nchars the sentence

" ‘chars’ The number of human-readable characters. "

with for example

" ‘chars’ The number of logical, possibly non-printable characters. " 

To clarify, the example section could include something like this:

nchar(c("hello","world"))
nchar("hello\nworld")


[1] http://r.789695.n4.nabble.com/nchar-reporting-wrong-width-when-zero-space-character-is-present-td4699779.html