0

For starters, I have set the option Tools/Global Options/R markdown evaluate chunks in directory project. So, the paths should be relative to the project. I use the following code format in the chunk:

```{r figure}
#| fig.cap=cap,
#| echo=FALSE
    
knitr::include_graphics(here("relative/path/to/figure.png"))
cap <- "Figure caption."
```

The error looks like:

Error in knitr::include_graphics(here("relative/path/to/figure.png")):
  Cannot find the file(s): "../../../relative/path/to/figure.png"

...

The previous paths on the chunks work, if I move to the rmarkdown location in the terminal and I go up three positions (as it is in the error) the path is still correct.

I just do not understand why this error keeps appearing.

Any help will be appreciated,

Thank you

Daniel Estévez
  • 113
  • 1
  • 11
  • 1
    Solutions here might help https://stackoverflow.com/questions/75458365/knitrinclude-graphics-cant-find-file-if-knitr-root-dir-is-changed and here https://stackoverflow.com/questions/57520181/rmarkdown-cannot-insert-image-with-knitrinclude-graphics-after-r-updated – user63230 Mar 21 '23 at 14:57

1 Answers1

0

In case you find this, the solution, as pointed in one of the links given by user63230, is to set rel_path = FALSE in the include_graphics function.

Julian
  • 6,586
  • 2
  • 9
  • 33
Daniel Estévez
  • 113
  • 1
  • 11