R Markdown not knitting when I add a new plot - r

My R markdown file is working fine, until I add a particular plot, then it will not knit and displays the following error:
! LaTeX Error: File `filename_files/figure-latex/unnamed-chunk-2-1' not found.
When I remove the plot, the file knits, when i include it, it doesn't knit. Here is the code I'm using for the plot:
```{r echo=FALSE}
plot(x=variable1,y=variable2,main="plot title")
```
I'm at a loss as to why this isn't working, when I've got other plots in the document that are displaying fine and are knitting in the pdf.

Rather frustratingly, I have managed to get around the issue by copying all of the text into a new document, and then trying to knit, and it worked straight away... However, after a while, the same issue kept occurring, this time with a different plot. A further workaround seemed to be rebooting the laptop. Again, I'm not entirely sure what is causing the issue, but it was occurring intermittently and without warning.

Related

Cannot knit in Rmarkdown because of error

So some reason I am able to knit my R markdown file into a Word doc. I don't know what to do or how to get over it. I keep getting the message in the picture about the code also listed there.

Can't knit in R markdown

Recently I was doing a course in Coursera and faced the problem while doing R markdown. When I run the code in the console it works just fine however, when I knit it, the rmarkdown only show text in the code chunk as below.
I run this in console and it work just fine:
But when i knit the code appear as text:
When I hit the green arrow it appears like there are some error going on:
The bottom screenshot you provided is not an R code chunk. It does not have the proper header. R code chunks in an R markdown file must be formatted like this:
```{r}
R code goes here
```

Knit PDF produced PDF different than Source in RStudio

When I knit PDF on RStudio. It DOES NOT match what is in my Rmd file after source of the .Rmd. This has happened every time I tried to Knit PDF. How can I get example what is in my .Rmd into Knit PDF? I've tried clearing cache and restarting RStudio but this inconsistency is still happening...
You need to set.seed() at instance where you are generating random data if you are generating any.
Try to clean your environment and rerun and assess results
Try to set.seed at the top of the code and rerun.

Saving AND showing plots in rmd file

I'm working on a rather long code using R markdown, divided into chunks. Plot appear under the appropriate chunk. I'd like to keep this behaviour, but additionally I want to save them to a specified folder. I've tried different methods listed here How to save a plot as image on the disk? (and elsewhere on the Internet), but nothing seems to work.
My reproducible example:
png('cars_plot.png')
plot(cars)
dev.off()
This code saves the plot, but doesn't show it (it only returns "null device 1"). I've also tried dev.print and dev.copy, with the same result.
Thank you in advance!
Clarification: I run my chunks one by one, I don't want to convert my results to pdf/html yet. So knitr: include figures in report *and* output figures to separate files or change where rmarkdown saves images generated by r code don't answer my question.
You can always graph it twice in the same markdown chunk, like this:
plot(cars)
png('cars_plot.png')
plot(cars)
dev.off()

render SQL in Rmarkdown notebook, not just when knit

If I have an R block in an Rmarkdown notebook, the code is visible in the rendered nb.html file. However, if I have a SQL block, I can't find a way to make the code visible in the rendered file.
However, if I generate an html_document (standard knitr) instead of an html_notebook, the rendered HTML does include the SQL code (and output).
Is there a way to get the notebook output to do something closer to what the knit output does?
I've also encountered this recently, Harlan, and began by asking if there's a way to get notebook output more like knit output.
I then wondered if there was a way to get knit output more like notebook output and realised that there was.
After asking the folks at RStudio, I learnt that you can add the following line to the YAML options in order to generate a html_document that, when rendered, enables the RMD to be downloaded. Specifically, use:
output:
html_document:
code_download: true
I now use that in all of my code and it works well. I hope it helps you, too.

Resources