[R] Bug with writeClipboard in {utils}

Rui Barradas ru|pb@rr@d@@ @end|ng |rom @@po@pt
Wed Jun 19 19:26:16 CEST 2024


Às 11:12 de 18/06/2024, Barthelemy Tanguy via R-help escreveu:
> Hello,
> 
> I'm encountering what seems to be a bug when using the `writeClipboard()` function in the R {utils} package.
> When I try to copy text to the clipboard, I notice that I get extra characters when I try to paste it (by hand with CTRL+V or with the `readClipboard()` function from R packages {utils}).
> 
> Here's my example:
> 
> ``` r
> utils::writeClipboard("plot(AirPassengers)")
> for (k in 1:10) {
>      print(utils::readClipboard())
> }
> #> [1] "plot(AirPassengers)" "⤀攀"
> #> [1] "plot(AirPassengers)" "\u0a00"
> #> [1] "plot(AirPassengers)" "\xed\xb0\x80ư"
> #> [1] "plot(AirPassengers)"
> #> [1] "plot(AirPassengers)"
> #> [1] "plot(AirPassengers)"
> #> [1] "plot(AirPassengers)"
> #> [1] "plot(AirPassengers)"
> #> [1] "plot(AirPassengers)" "⤀"
> #> [1] "plot(AirPassengers)"
> Message d'avis :
> Dans utils::readClipboard() : unpaired surrogate Unicode point dc00
> ```
> 
> So I don't always get the same result.
> I opened a problem in the {clipr} GitHub repository before realizing it's a {tools} problem: https://github.com/mdlincoln/clipr/issues/68
> 
> Is this a bug or something I haven't configured properly?
> 
> 
> Thank you very much
> 
> 
> Tanguy BARTHELEMY
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Hello,

I have reproduced part of the behavior in the OP but it will depend on 
the GUI or command line used.

With Rscript or with R I haven't found any errors.
With Rgui or with RStudio, yes, the output was not the expected output.

All code run in R 4.4.0 on Windows 11.

The script rscript.R is


utils::capture.output({
utils::writeClipboard("plot(AirPassengers)")
for (k in 1:10) {
   print(utils::readClipboard())
}
sessionInfo()
}, file = "rhelp.txt")


---

Here are the results I got.

1) Command:

Rscript rscript.R

Output:

[1] "plot(AirPassengers)"
[1] "plot(AirPassengers)"
[1] "plot(AirPassengers)"
[1] "plot(AirPassengers)"
[1] "plot(AirPassengers)"
[1] "plot(AirPassengers)"
[1] "plot(AirPassengers)"
[1] "plot(AirPassengers)"
[1] "plot(AirPassengers)"
[1] "plot(AirPassengers)"
R version 4.4.0 (2024-04-24 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 22631)

Matrix products: default


locale:
[1] LC_COLLATE=Portuguese_Portugal.utf8 
LC_CTYPE=Portuguese_Portugal.utf8
[3] LC_MONETARY=Portuguese_Portugal.utf8 LC_NUMERIC=C 

[5] LC_TIME=Portuguese_Portugal.utf8

time zone: Europe/Lisbon
tzcode source: internal

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

loaded via a namespace (and not attached):
[1] compiler_4.4.0

---

2) Command:
R -q -f rscript.R

Output:

 > utils::writeClipboard("plot(AirPassengers)")
 > for (k in 1:10) {
+     print(utils::readClipboard())
+ }
[1] "plot(AirPassengers)"
[1] "plot(AirPassengers)" "㨀Ǐ\005"
[1] "plot(AirPassengers)"
[1] "plot(AirPassengers)"
[1] "plot(AirPassengers)"
[1] "plot(AirPassengers)"
[1] "plot(AirPassengers)"
[1] "plot(AirPassengers)"
[1] "plot(AirPassengers)"
[1] "plot(AirPassengers)"
 > sessionInfo()
R version 4.4.0 (2024-04-24 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 22631)

Matrix products: default


locale:
[1] LC_COLLATE=Portuguese_Portugal.utf8 
LC_CTYPE=Portuguese_Portugal.utf8
[3] LC_MONETARY=Portuguese_Portugal.utf8 LC_NUMERIC=C 

[5] LC_TIME=Portuguese_Portugal.utf8

time zone: Europe/Lisbon
tzcode source: internal

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

loaded via a namespace (and not attached):
[1] compiler_4.4.0
 >

---

3) GUI: RStudio
Output:

[1] "plot(AirPassengers)"
[1] "plot(AirPassengers)" "礀摟瑡扡獡e"
[1] "plot(AirPassengers)"
[1] "plot(AirPassengers)" "봀翿"
[1] "plot(AirPassengers)" "礀摟瑡扡獡e"
[1] "plot(AirPassengers)"
[1] "plot(AirPassengers)"
[2] "礀摟瑡扡獡eX泙瑢ᄀ耀㜰戲扡捤㔭挷ⴱ㘴㍦戭㜱ⴰ慣㈶㜸㍥捣攳Ȁ"
[1] "plot(AirPassengers)" "촀˖"
[1] "plot(AirPassengers)"
[1] "plot(AirPassengers)"
R version 4.4.0 (2024-04-24 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 22631)

Matrix products: default


locale:
[1] LC_COLLATE=Portuguese_Portugal.utf8 
LC_CTYPE=Portuguese_Portugal.utf8
[3] LC_MONETARY=Portuguese_Portugal.utf8 LC_NUMERIC=C 

[5] LC_TIME=Portuguese_Portugal.utf8

time zone: Europe/Lisbon
tzcode source: internal

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

loaded via a namespace (and not attached):
  [1] gtable_0.3.4         tensorA_0.36.2.1     ggplot2_3.5.0
  [4] QuickJSR_1.1.3       processx_3.8.3       inline_0.3.19
  [7] lattice_0.22-5       tzdb_0.4.0           callr_3.7.5
[10] vctrs_0.6.5          tools_4.4.0          ps_1.7.6
[13] generics_0.1.3       stats4_4.4.0         curl_5.2.1
[16] parallel_4.4.0       sandwich_3.1-0       tibble_3.2.1
[19] fansi_1.0.6          chron_2.3-61         pkgconfig_2.0.3
[22] brms_2.21.0          Matrix_1.6-5         checkmate_2.3.1
[25] distributional_0.4.0 RcppParallel_5.1.7   lifecycle_1.0.4
[28] compiler_4.4.0       stringr_1.5.1        Brobdingnag_1.2-9
[31] munsell_0.5.0        codetools_0.2-19     bayesplot_1.11.1
[34] pillar_1.9.0         crayon_1.5.2         MASS_7.3-60.0.1
[37] StanHeaders_2.32.6   bridgesampling_1.1-2 abind_1.4-5
[40] multcomp_1.4-25      nlme_3.1-164         posterior_1.5.0
[43] rstan_2.32.5         tidyselect_1.2.0     mvtnorm_1.2-3
[46] stringi_1.7.12       dplyr_1.1.4          splines_4.4.0
[49] grid_4.4.0           colorspace_2.1-0     cli_3.6.2
[52] magrittr_2.0.3       loo_2.6.0            survival_3.5-8
[55] pkgbuild_1.4.2       utf8_1.2.4           TH.data_1.1-2
[58] readr_2.1.4          prettyunits_1.2.0    scales_1.3.0
[61] backports_1.4.1      estimability_1.5     httr_1.4.7
[64] matrixStats_1.0.0    emmeans_1.10.0       gridExtra_2.3
[67] hms_1.1.3            zoo_1.8-12           coda_0.19-4.1
[70] V8_4.4.2             rstantools_2.3.1.1   rlang_1.1.3
[73] Rcpp_1.0.12          xtable_1.8-4         glue_1.7.0
[76] ppcor_1.1            rstudioapi_0.15.0    jsonlite_1.8.8
[79] R6_2.5.1

---

4) GUI: Rgui
Output:

[1] "plot(AirPassengers)" "က \005ⷀǏǭ"
[1] "plot(AirPassengers)"
[1] "plot(AirPassengers)"
[1] "plot(AirPassengers)"
[1] "plot(AirPassengers)"
[1] "plot(AirPassengers)"
[1] "plot(AirPassengers)"
[1] "plot(AirPassengers)"
[1] "plot(AirPassengers)"
[1] "plot(AirPassengers)"
R version 4.4.0 (2024-04-24 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 22631)

Matrix products: default


locale:
[1] LC_COLLATE=Portuguese_Portugal.utf8 
LC_CTYPE=Portuguese_Portugal.utf8
[3] LC_MONETARY=Portuguese_Portugal.utf8 LC_NUMERIC=C 

[5] LC_TIME=Portuguese_Portugal.utf8

time zone: Europe/Lisbon
tzcode source: internal

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

loaded via a namespace (and not attached):
[1] compiler_4.4.0



Hope this helps,

Rui Barradas




-- 
Este e-mail foi analisado pelo software antivírus AVG para verificar a presença de vírus.
www.avg.com



More information about the R-help mailing list