Search code examples
pdfr-markdownpngknitrpapaja

Rmarkdown can't find a .png image while trying to compile on pdf using papaja


I am trying to make a document using papaja format in r-markdown. The problem is R can't compile the pdf because it cannot find an image I am trying to import using `knitr::include_graphics().

This is my Yaml header:

---
title             : "Something"
author: 
  - name          : "my name"
bibliography      : ["Draft.bib"]
floatsintext      : yes
figsintext        : yes
figurelist        : no
tablelist         : no
footnotelist      : no
linenumbers       : yes
link-citations    : yes
mask              : no
draft             : no
documentclass     : "apa6"
classoption       : "man"
output            : 
  pdf_document : papaja::apa6_pdf
header-includes:
  - \usepackage{setspace}
  - \AtBeginEnvironment{tabular}{\singlespacing}
  - \AtBeginEnvironment{lltable}{\single  espacing}
  - \AtBeginEnvironment{tablenotes}{\doublespacing}
  - \captionsetup[table]{font={stretch=1.5}}
  - \captionsetup[figure]{font={stretch=1.5}}
---

This is the chunk where I am trying to import the image:

```{r colors}
knitr::include_graphics("figures/colors.png")
```

Note that I have already checked my wd, and that there are not any spaces in the path of my image

And finally this is what R prints as an error while trying to compile:

!!! Error: Input file `Draft_files/figure-latex/colors-1.pdf' not found!

Quitting from lines 87-88 (Draft.Rmd) 
Error in magick_image_readpath(enc2native(path), density, depth, strip) : 
  R: unable to open image `Draft_files/figure-latex/colors-1.png': No such file or directory @ error/blob.c/OpenBlob/2874
Calls: <Anonymous> ... in_dir -> plot_crop -> <Anonymous> -> magick_image_readpath
Execution halted

I have also tried to change the path to ./figures/colors.png but the result is the same.

Any help will be pretty much appreciated!


Solution

  • This is a known bug that has been fixed in the development version of knitr. Please either try the dev version

    remotes::install_github('yihui/knitr')
    

    or wait for the next version of knitr (v1.28) to appear on CRAN (hopefully in a few days).

    Alternatively, you may set the chunk option crop=NULL on the chunk, e.g.

    ```{r colors, crop=NULL}