mdlincoln / clipr

R functions for reading and writing from the system clipboard
http://matthewlincoln.net/clipr/
152 stars 24 forks source link

`write_clip()` adds some character #68

Open TanguyBarthelemy opened 4 months ago

TanguyBarthelemy commented 4 months ago

I try to use write_clip() with some string. When I call read_clip(), I get different results without changing the clipboard value:

library("clipr")
#> Welcome to clipr. See ?write_clip for advisories on writing to the clipboard in R.

write_clip("plot(AirPassengers)", allow_non_interactive = TRUE)
read_clip(allow_non_interactive = TRUE)
#> [1] "plot(AirPassengers)" "爀役慤慴慢敳"
read_clip(allow_non_interactive = TRUE)
#> [1] "plot(AirPassengers)" "嘀翶"
read_clip(allow_non_interactive = TRUE)
#> [1] "plot(AirPassengers)"
read_clip(allow_non_interactive = TRUE)
#> [1] "plot(AirPassengers)"                                     "爀浡≳嬺〳㤶ⱝ煚⩩退㈵㌷ㄹ〲昭㘰ⴶ搴愹愭㈰ⵢ㘵㔶〶昹ㄱ昵䔀)"

Also if I call utils::readClipboard(), I get the same results.

However, when I just paste the results with Ctrl + v (on Windows), every time I get plot(AirPassengers) with a new line (the expected result).

Also when I copy by hand and use read_clip(), I never get the additionnal character...

Thank you very much!

TanguyBarthelemy commented 3 months ago

I just tested the function utils::writeClipboard() and I get the same problem. I've also realised that it depends on the length of my character chain and the content! For example, strings of length 9 are not affected by this change...