[R-SIG-Mac] Clipboard problems
    peter dalgaard 
    pdalgd at gmail.com
       
    Wed Sep  3 14:29:38 CEST 2014
    
    
  
On 03 Sep 2014, at 13:56 , Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
> The standard advice for reading the clipboard on OSX is to use the
> pipe("pbpaste") connection, but I'm finding it misses the last line.  (I
> believe the last line in my examples generally doesn't include any EOL
> marker.)  For example, if I highlight these three lines:
> 
> line 1
> line 2
> line 3
> 
> and copy to the clipboard, then readLines(pipe("pbpaste")) gives
> 
> [1] "line 1" "line 2"
> 
> in R.app or R in a terminal.  If I paste them here, I get
> 
> line 1
> line 2
> line 3
> 
> with the cursor left on the third line after the 3.  In a console, echo
> `pbpaste` gives
> 
> line 1 line 2 line 3
> 
> so the problem isn't (only) with pbpaste.
> 
I think that the issue is that the last line is incomplete and pipe() is non-blocking
E.g.,
Peters-iMac:R-docs pd$ pbpaste
line 1
line 2
line 3Peters-iMac:R-docs pd$ 
and (with the same clipboard)
> readLines(pipe("pbpaste"))
[1] "line 1" "line 2"
pushes back the incomplete line, hoping that it might be available for a later read. (It takes someone smarter than me to say whether this is unavoidable or whether pipe() should be able to detect that the
command has completed.)
This works, presumably because text connections are not non-blocking:
> readLines(textConnection(system("pbpaste",intern=TRUE)))
[1] "line 1" "line 2" "line 3"
-pd
> Duncan Murdoch
> 
> _______________________________________________
> R-SIG-Mac mailing list
> R-SIG-Mac at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac
-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com
    
    
More information about the R-SIG-Mac
mailing list