Discussion:
[R-SIG-Mac] Clipboard problems
Duncan Murdoch
2014-09-03 11:56:33 UTC
Permalink
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.

Duncan Murdoch
Reijo Sund
2014-09-03 12:17:14 UTC
Permalink
Post by Duncan Murdoch
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.
How about using tcltk?

if (require("tcltk")) strsplit(tclvalue(tcl("clipboard","get")),"\n")[[1]]
peter dalgaard
2014-09-03 12:29:38 UTC
Permalink
Post by Duncan Murdoch
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
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)
Post by Duncan Murdoch
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.)
Post by Duncan Murdoch
readLines(textConnection(system("pbpaste",intern=TRUE)))
[1] "line 1" "line 2" "line 3"

-pd
Post by Duncan Murdoch
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
Hans-Jörg Bibiko
2014-09-03 13:05:55 UTC
Permalink
Post by Duncan Murdoch
readLines(textConnection(system("pbpaste",intern=TRUE)))
[1] "line 1" "line 2" "line 3?
or the following should also work on each OSX

readLines(pipe("pbpaste|awk 1?))


Cheers,
Hans




******************************************************
Hans-Joerg Bibiko
Max Planck Institute for Evolutionary Anthropology
Department of Linguistics
Deutscher Platz 6 phone: +49 (0) 341 3550 341
D-04103 Leipzig fax: +49 (0) 341 3550 333
Germany e-mail: bibiko [at] eva.mpg.de
Adrian Dușa
2014-09-03 13:10:18 UTC
Permalink
Post by peter dalgaard
[...]
Post by Duncan Murdoch
readLines(textConnection(system("pbpaste",intern=TRUE)))
[1] "line 1" "line 2" "line 3"
system("pbpaste",intern=TRUE)
[1] "line 1" "line 2" "line 3"
--
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania
Loading...