[Rd] Clarification for readChar man page

Duncan Murdoch murdoch at stats.uwo.ca
Thu Jun 14 17:11:29 CEST 2007

On 6/14/2007 10:49 AM, Jeffrey Horner wrote:
> Hi,
> Here's a patch to the readChar manual page (R-trunk as of today) that 
> better clarifies readChar's return value. 

Your update is not right.  For example:

x <- as.raw(32:96)
readChar(x, nchars=rep(2,100))

This returns a character vector of length 100, of which the first 32 
elements have 2 chars, the next one has 1, and the rest are "".

So the length of nchars really does affect the length of the value.

Now, I haven't looked at the code, but it's possible we could delete the 
"(which might be less than \code{length(nchars)})" remark, and if not, 
it would be useful to explain the situations in which the return value 
could be shorter than the nchars vector.

Duncan Murdoch

It could use some work as I'd
> also like to add some text about using nchar() to find the length of the 
> string that readchar() returns, but I'm unsure which of type="bytes" or 
> type="chars" to mention. Is it type="chars"?
> Index: src/library/base/man/readChar.Rd
> ===================================================================
> --- src/library/base/man/readChar.Rd    (revision 41943)
> +++ src/library/base/man/readChar.Rd    (working copy)
> @@ -57,8 +57,8 @@
>   }
>   \value{
> -  For \code{readChar}, a character vector of length the number of
> -  items read (which might be less than \code{length(nchars)}).
> +  For \code{readChar}, a character vector of length 1 with the number
> +  of characters less than or equal to nchars.
>     For \code{writeChar}, a raw vector (if \code{con} is a raw vector) or
>     invisibly \code{NULL}.
> Jeff

More information about the R-devel mailing list