Insert copy to clipboard buttons in RMarkdown HTML documents

Common use

The klippy package enhances R Markdown HTML documents with copy to clipboard buttons. You only have to paste the following chunk anywhere in your Rmd file.

Obviously, you have to try the clipboard button in the upper left corner of this chunk!

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

The klippy() function inserts a klippy1 in each R or markdown code block.

Code block selection

You can select which of the code blocks get a klippy.
First, insert this chunk anywhere in your Rmd file:

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

Then, add the klippy class to a code chunk:

```{r cars, class.source='klippy'}
summary(cars)
```

Engine selection

If you use other languages than R in your Rmd file, you can also add klippies to these code blocks.

For example, if you want to add klippies to R and python code blocks, add this chunk anywhere in your Rmd file:

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

Icon positioning

By default, klippy is positionned at the upper-left corner of the code chunks. You can choose another corner with position argument:

```{r klippy, echo=FALSE, include=TRUE}
klippy::klippy(position = c('top', 'right'))
```

Color customization

klippy color is the same as the links in the document. However, you can pick another color:

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

Tooltip messages

Tooltip messages can also be adapted:

```{r klippy, echo=FALSE, include=TRUE}
klippy::klippy(tooltip_message = 'Click to copy', tooltip_success = 'Done')
```

Browser Support

For supported browsers, see clipboard.js documentation.


  1. A klippy is a knitweaR clipboard button.↩︎