'Knit RMarkdown Image ! Package pdftex.def Error: File `~/folder/folder/filename.png' not found: using draft setting
I am having trouble knitting a pdf document with RMarkdown when embedding images. When using the markdown syntax below:

I get the error:
Package pdftex.def Error: File `~/folder/folder/filename.png' not found: using draft setting.
I have also tried:
``` {r results = 'asis'}
knitr::include_graphics(path = "~/folder/folder/filename.png")
```
And, I get the error:
Unescaped left brace in regex is passed through in regex; marked by <-- HERE in m//\nobreakspace { <-- HERE }/folder/folder/filename/ at C:\Users\NAME~1\AppData\Roaming\TinyTeX\texmf-dist\scripts\texlive\tlmgr.pl line 1847. Error in grep(paste0("/", x[j], "$"), l) : invalid regular expression '/\nobreakspace {}/folder/folder/filename$', reason 'Invalid contents of {}' Calls: ... system2_quiet -> on_error -> parse_packages -> grep In addition: Warning message: In grep(paste0("/", x[j], "$"), l) : TRE pattern compilation error 'Invalid contents of {}' Warning: LaTeX Warning: Reference `LastPage' on page 1 undefined on input line 153. Execution halted
I have tinytex installed, but maybe I am missing another LaTeX package? Any guidance would be appreciated.
Solution 1:[1]
First, as @samcarter_is_at_topanswers.xyz recommended above, the tilde character cannot be interpreted from Markdown to LaTeX.
Additionally, I had my markdown file in one subfolder and my images in another subfolder. When I was knitting the markdown file, the working directory changes to the subfolder that the markdown file is in causing the file path provided for the images to no longer be understood when using the path folder/folder/filename.png. You can either move the markdown file to the main directory or set the entire file path.
If you move the markdown file to the main directory the file path can look like:

or keep in the subfolder and use:

The same goes for using knitr's include_graphics function.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
