Bug 14593 - readChar from clipboard connection does not advance position
readChar from clipboard connection does not advance position
Status: CLOSED FIXED
Product: R
Classification: Unclassified
Component: I/O
R-devel (trunk)
All Linux
: P5 enhancement
Assigned To: R-core
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-05-26 17:21 UTC by Mikko Korpela
Modified: 2011-05-30 09:28 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 Mikko Korpela 2011-05-26 17:21:01 UTC
Overview:

The function readChar is "intended to be used with binary-mode connections". However, I see no reason why it could not work for reading from clipboard, which is necessarily a text-mode connection. Presently, when used on a clipboard connection, readChar does not advance the current position. Thus, consecutive identical readChar calls will return identical results. Also, when useBytes is FALSE (the default), readChar returns nchars copies of the first character on the clipboard.

Steps to Reproduce:

1) Start R
2) Copy to clipboard the text "R is free software and comes with ABSOLUTELY NO WARRANTY."
3) Open a connection to the clipboard
clp <- file("clipboard", open="r")
4) Read nine characters, useBytes=FALSE
readChar(clp, nchars=9, useBytes=FALSE)
5) Repeat
readChar(clp, nchars=9, useBytes=FALSE)
6) Read nine characters, useBytes=TRUE
readChar(clp, nchars=9, useBytes=TRUE)
7) Repeat
readChar(clp, nchars=9, useBytes=TRUE)

Actual Results:

> clp <- file("clipboard", open="r")
> readChar(clp, nchars=9, useBytes=FALSE)
[1] "RRRRRRRRR"
> readChar(clp, nchars=9, useBytes=FALSE)
[1] "RRRRRRRRR"
> readChar(clp, nchars=9, useBytes=TRUE)
[1] "R is free"
> readChar(clp, nchars=9, useBytes=TRUE)
[1] "R is free"

Expected Results:

> clp <- file("clipboard", open="r")
> readChar(clp, nchars=9, useBytes=FALSE)
[1] "R is free"
> readChar(clp, nchars=9, useBytes=FALSE)
[1] " software"
> readChar(clp, nchars=9, useBytes=TRUE)
[1] " and come"
> readChar(clp, nchars=9, useBytes=TRUE)
[1] "s with AB"

This is also the result one gets by creating a text file with the same contents, opening a text or binary mode connection to the file, and using the same sequence of readChar commands.

Build Date & Platform:

> sessionInfo()
R version 2.14.0 Under development (unstable) (2011-05-25 r55988)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=C                 LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

Additional Information:

The cause of the unintuitive behavior is in connections.c, function clp_read. A proposed fix can be found in the attachment of bug 14494 which was classified as WONTFIX, but maybe this smaller individual issue is a good candidate to get fixed.

- Mikko Korpela
Comment 1 Brian Ripley 2011-05-28 09:13:48 UTC
NB: although you marked this as *all*, the underlying mechanisms are
OS-dependent, and indeed not even implemented on all OSes.

You are also asked to use R-bugs to report on released versions, R-devel for the unreleased development version.
Comment 2 Mikko Korpela 2011-05-30 09:28:31 UTC
(In reply to comment #1)
> NB: although you marked this as *all*, the underlying mechanisms are
> OS-dependent, and indeed not even implemented on all OSes.

The bug (or "enhancement") also affects R on OS X (reading from the X11 clipboard is possible there also), at least version 2.13.0 (2011-04-13). Bug Writing Guidelines suggest choosing "All" if the bug happens on more than one type of operating system.

> You are also asked to use R-bugs to report on released versions, R-devel for
> the unreleased development version.

I assume you mean I should use a mailing list instead of the Bugzilla form. In that case, I'm confused why claiming a bug in the development version is even an option in the Version field of the Bugzilla form.