rr-markdownmarkdown

How to insert the "Copy to clipboard" icon in an r markdown document


I want to insert the Copy to clipboard icon in my chunks and instead of a complicated description just see the image, which is a screenshot of chapter 3.1 of the R Markdown Cookbook.

My code (with the missing lines of code to get that icon and tooltip like in the image):

---
title: "First R Markdown Document"
author: "My name"
date: "Last edited: `r format(Sys.time(), '%d.%m.%Y')`"
output: html_document
---

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents.

You can embed an R code chunk like this:

```{r, echo=TRUE}
summary(cars)
```

You can also embed plots, for example:

```{r, echo=TRUE}
plot(cars)
```

All I found is using the package klippy - but that's an other approach (or?!).

Thanks a lot in advance!

enter image description here


Solution

  • It seems that this particular button is only available with the bookdown::gitbook() format (or natively with Quarto). So you need :

    install.packages("bookdown"), then :

    ---
    title: "First R Markdown Document"
    author: "My name"
    date: "Last edited: `r format(Sys.time(), '%d.%m.%Y')`"
    output: bookdown::gitbook
    ---
      
    This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents.
    
    You can embed an R code chunk like this:
      
    ```{r, echo=TRUE}
    summary(cars)
    ```
    
    You can also embed plots, for example:
      
    ```{r, echo=TRUE}
    plot(cars)
    ```