Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rstudio does not make plots with knit Word

I seem to have discovered an odd behaviour with the knit Word command in RStudio

This works:

 ```{r qplot, fig.width = 6, fig.height=6, message=FALSE}
 library(ggplot2)
 summary(cars)
 qplot(speed, dist, data = cars) + geom_smooth()
 ````

this does not work

 ```{r q plot, fig.width = 6, fig.height=6, message=FALSE}
 library(ggplot2)
 summary(cars)
 qplot(speed, dist, data = cars) + geom_smooth()
 ```

returning this message:

 pandoc.exe: Could not find image `./test_files/figure-docx/q%20plot.png', skipping...

The issue seems to be with the name of the chunk (i.e. qplot vs. q plot). When there is a space in the chunk name the plot does not render.

It only seems to affect the rendering of Word documents. Rendering html works fine.

I'm using RStudio 0.98.1028 and R3.1.1 on windows 7.

Has anyone else encountered this behaviour?

update

a space after the chunk name also seems to elicit the same behaviour:

this does not work

 ```{r q_plot , fig.width = 6, fig.height=6, message=FALSE}
 library(ggplot2)
 summary(cars)
 qplot(speed, dist, data = cars) + geom_smooth()
 ```
like image 315
Chris Avatar asked Oct 21 '22 02:10

Chris


1 Answers

Posting the solution in case someone runs across this in future.

From Ben Bolker in the comments Avoid spaces and periods . in chunk labels and directory names as stated in the knitr documentation http://yihui.name/knitr/options.

This error only seems to affect making plots using knitWord. Code chunks with labels that contain spaces and that don't have plotting commands render normally. knitHTML also seems to work fine regardless of if chunk labels have a space or not.

like image 134
Chris Avatar answered Oct 24 '22 11:10

Chris