Omry Atia
Omry Atia

Reputation: 2443

Error while knitting an rmarkdown document - cannot find figure

I am trying to manually knit an rmd document which calls a figure fig1.gif.

! Unable to load picture or PDF file 'fig1.gif'.
<to be read again> 
               }
l.91 \includegraphics{fig1.gif}

The way I call the figure is:

![](fig1.gif)

The figure DOES exist in the directory. Any idea what the problem might be?

Upvotes: 1

Views: 1477

Answers (1)

Sal-laS
Sal-laS

Reputation: 11649

I don't have your code, but i can give you 2 hints:

  1. Make sure that your file is next to your markdown file in the same directory.
  2. Try relative pathof the file.
  3. Write a short snippet which checks if R can find your file.

I found a sample from this question.

        imgAddress="./ADDRESS bla bla/fig1.gif"     
         if (!file.exists(imgAddress)) {
            print("File is not found") }
         }

I should cast doubt on the way which you load the image. There are several packages which ,may help you:

library(magick)
tiger <- image_read_svg('http://jeroen.github.io/images/tiger.svg', width = 400)
print(tiger)

OR

earth <- image_read("https://jeroen.github.io/images/earth.gif") %>%
  image_scale("200x") %>%
  image_quantize(128)

length(earth)

Please read the below link. it will be usefull.

https://cran.r-project.org/web/packages/magick/vignettes/intro.html

Upvotes: 2

Related Questions