Copy to Clipboard with kable() giving incorrect screenshot

I am trying to use the Export -> Copy to Clipboard option after making a kable() table. When I go to paste elsewhere, the clipboard image taken is a weird mix of my desktop with only part of the table. I have double checked and this does not happen when I try to do the same thing with ggplot(). I've attached my code as an example and what I receive as my output. I have instead been saving these plots as images (and this works fine!) but I really don't need these plots/just would like to copy them.

Code:

hectare <- PlantGrowth %>% 
  mutate(hectare = weight/10000)
partbtab <- hectare %>% 
  group_by(group) %>% 
  summarise("Mean/Yr" = mean(hectare),
            "25 Year Average" = `Mean/Yr`*25)
kable(partbtab) %>% 
  kableExtra::kable_styling()

Clipboard image produced:
image

Update: this is also happening if I use gt().

Hi @allie_case3
I cannot reproduce your problem. When I paste the copied plot into Microsoft Word it looks fine (although there is a lot of blank space at the bottom of the image which can quickly be removed with [crop].

> RStudio.Version()$version
[1] ‘2022.12.0.353’

> sessionInfo()
R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22621)

Matrix products: default

locale:
[1] LC_COLLATE=English_Australia.utf8  LC_CTYPE=English_Australia.utf8    LC_MONETARY=English_Australia.utf8
[4] LC_NUMERIC=C                       LC_TIME=English_Australia.utf8    

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

other attached packages:
 [1] knitr_1.41      forcats_0.5.2   stringr_1.5.0   dplyr_1.0.10    purrr_1.0.0     readr_2.1.3    
 [7] tidyr_1.2.1     tibble_3.1.8    ggplot2_3.4.0   tidyverse_1.3.2

loaded via a namespace (and not attached):
 [1] svglite_2.1.0       lubridate_1.9.0     assertthat_0.2.1    digest_0.6.31       utf8_1.2.2         
 [6] R6_2.5.1            cellranger_1.1.0    backports_1.4.1     reprex_2.0.2        evaluate_0.19      
[11] httr_1.4.4          highr_0.10          pillar_1.8.1        rlang_1.0.6         googlesheets4_1.0.1
[16] readxl_1.4.1        rstudioapi_0.14     jquerylib_0.1.4     rmarkdown_2.19      webshot_0.5.4      
[21] googledrive_2.0.0   munsell_0.5.0       broom_1.0.2         compiler_4.2.2      modelr_0.1.10      
[26] xfun_0.36           pkgconfig_2.0.3     systemfonts_1.0.4   htmltools_0.5.4     tidyselect_1.2.0   
[31] fansi_1.0.3         viridisLite_0.4.1   crayon_1.5.2        tzdb_0.3.0          dbplyr_2.2.1       
[36] withr_2.5.0         grid_4.2.2          jsonlite_1.8.4      gtable_0.3.1        lifecycle_1.0.3    
[41] DBI_1.1.3           magrittr_2.0.3      scales_1.2.1        cachem_1.0.6        cli_3.5.0          
[46] stringi_1.7.8       fs_1.5.2            xml2_1.3.3          bslib_0.4.2         ellipsis_0.3.2     
[51] generics_0.1.3      vctrs_0.5.1         kableExtra_1.3.4    tools_4.2.2         glue_1.6.2         
[56] hms_1.1.2           fastmap_1.1.0       timechange_0.2.0    colorspace_2.0-3    gargle_1.2.1       
[61] rvest_1.0.3         haven_2.5.1         sass_0.4.4

Hello, thank you for attempting this. I am curious if this is a Mac vs PC issue. I have had other colleagues try this and similarly, they do not have this issue. Working backwards, do you have any recommendations of what it could be on my end? Display settings, Mac OS, etc. ?

I think the problem is due to the Viewer pane in RStudio not being large enough (I think I see part of a scroll bar in your screenshot). If I "scrunch-up" my Viewer pane and then Export/Copy I get the same problem.

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.