1

Similar questions have been asked before about inserting an image from a url (for example here and here ). However, I can't seem to get those solutions to work for me.

I am trying to create an R package vignette and a github.io vignette page. Initially I was saving my images to my machine and when building the vignette I was calling them locally via:

knitr::include_graphics("file/path/image.png")

However, when I use devtools::build_site() to build the github.io site, the images are understandably missing from the vignette. I have uploaded all the images to my GitHub repo and I was wondering if there is any way to display to these images when building the GitHub.io site?

I have tried the following but neither have worked. I just get a blank space where the image should be.

<center><src="https://github.com/tidyverse/ggplot2/blob/main/icons/coord_cartesian.png"></center>

```{r out.width="100%"}
url <- "https://github.com/tidyverse/ggplot2/blob/main/icons/coord_cartesian.png"
knitr::include_graphics(url)

```

My YAML looks like this:

---
title: "myPackage"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{vivid}
  %\VignetteEncoding{UTF-8}
  %\VignetteEngine{knitr::rmarkdown}
editor_options: 
  chunk_output_type: console
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "vig/"
)
options(rmarkdown.html_vignette.check_title = FALSE)
```
Electrino
  • 2,636
  • 3
  • 18
  • 40

1 Answers1

1

I figured out the solution to my problem from this. I needed to use the "raw" absolute link from the image. So in the example above, I should have used:

```{r out.width="100%"}
url <- "https://raw.githubusercontent.com/tidyverse/ggplot2/main/icons/coord_cartesian.png"
knitr::include_graphics(url)

```
Electrino
  • 2,636
  • 3
  • 18
  • 40