0

I'm hoping there is a simple solution, apologies if I haven't provided enough information - please let me know if I should add any other info.

I'm trying to render two pngs to a pdf. When I manually knit to PDF in RStudio, the images are included as expected. However, when I try to use the Rmarkdown::render function the pdf shows

![](up-arrow.png) 

as text instead of the image.

Here is my rmd:

---
fontfamily: helvet
geometry: margin=0.5in
header-includes:
- \usepackage{booktabs}
- \usepackage{longtable}
- \usepackage{array}
- \usepackage{multirow}
- \usepackage{wrapfig}
- \usepackage{float}
- \usepackage{colortbl}
- \usepackage{pdflscape}
- \usepackage{tabu}
- \usepackage{threeparttable}
- \usepackage{threeparttablex}
- \usepackage[normalem]{ulem}
- \usepackage{makecell}
- \usepackage{xcolor}
- \renewcommand{\familydefault}{\sfdefault}
output:
  pdf_document:
    latex_engine: pdflatex
---

```{r message=FALSE, warning=FALSE}
library(knitr)
df <- data.frame(
  stock = c('Apple','Amazon','Microsoft','Tesla'),
  value = c(300,200,150,250),
  difference = c(50,-10,20,-15)
)
df$trend <- ifelse(df$difference >0,
                   '![](up-arrow.png)',
                   '![](down-arrow.png)'
                  )

kable(df)

```

I don't receive any error that it can't find the pngs, and it doesn't appear that it's even looking. Here is how I'm using the render function, I've tried adding an output_file and output_dir argument but neither do the trick. I also added envir = new.env() to guarantee an empty new environment as recommended here: Why does rendering a pdf from rmarkdown require closing rstudio between renders?, but that did not work either.

rmarkdown::render('C:/Users/Desktop/Notes/test.Rmd',pdf_document(latex_engine = "pdflatex"), envir = new.env())
David
  • 432
  • 3
  • 10
  • Try results='asis' in the code chunk params and then knit (this assumes that the path is valid to the figures from wherever knitr thinks the project root is) – MDEWITT Dec 02 '19 at 23:08
  • That did not work sadly. I found that if I restart my R session and run the render function it will actually print the images but ignores the kable function. All the values print in a single column. After I run it again after that first time, the results are the same as they were and it prints out the code but not the image. – David Dec 03 '19 at 16:28

0 Answers0