5

does the button to copy to cliboard exist with R markdown?

It exists in Quarto (with the code-copy option) enter image description here

and with pkgdown websites enter image description here but is it possible to add it to a R markdown or R notebook document?

olivroy
  • 548
  • 3
  • 13
  • 3
    Doesn't look like it unless it's been added very recently but suggests [here](https://community.rstudio.com/t/copy-to-clipboard-buttons-for-code-blocks/45367/5) to use `bookdown::html_document2()` instead to get this feature. – SamR Jul 27 '22 at 13:26
  • Is it possible to include this feature when the output is a beamer presentation? – user3856486 Apr 18 '23 at 09:12

1 Answers1

1

You could use the package klippy to insert a copy to clipboard button in Rmarkdown HTML documents. To only thing you need to do is add this code somewhere in your document:

```{r klippy, echo=FALSE, include=TRUE}
klippy::klippy()
```

To install the package, you can use the following code:

remotes::install_github("rlesur/klippy")
library(klippy)

Here is a reproducible example:

---
title: "Copy code to clipboard"
date: "2022-10-31"
output: html_document
---

```{r klippy, echo=FALSE, include=TRUE}
klippy::klippy()
```

Some example code:

```{r}
# Summary of mtcars dataset:
summary(mtcars)
```

Output:

enter image description here

As you can see a copy to clipboard button in the top left of the code chunk.


For more information check the documentation.

Quinten
  • 35,235
  • 5
  • 20
  • 53