False-positive messages in RStudio related to R chunks

I've encountered strange false-positive messages in RStudio when knitting a document. The message points to a chunk (indicating line xx) in the .Rmd document, and the document is not opened. The text of the message is completely obscure to me. When I remove the chunk (which wasn't a problem, say, yesterday) it then opens. I then re-insert the chunk and it continues to knit fine. This last happened to me when I was working with a Xaringan-related .Rmd.

I've also noticed the following in some .Rmd documents I see on the web:


I don't include those in my .Rmds (except for the "include = FALSE" one).

I don't know what the other options in the Red Boxes are. Can someone point to to guidance about these options ? If I include those related to "warning" and "message," will that preclude the false-positive occurrences ?



It's hard to diagnose what the root cause of the knitting message is (the "completely obscure" part of your question) without seeing the text of the message. So, a bit more detail is needed on the core description of your question.

I don't think the chunk options are the likely culprit, though, and almost certainly not the ones you highlighted. It's weird that it's always taken a bit of digging to get a comprehensive list of chunk options, but Yihui Xie does now have a pretty comprehensive page that explains them.

The knitr::opts_chunk$set() call simply sets default chunk options, but those can then be overridden for individual chunks. To the ones you outlined (and why I don't think they're directly at the root of the issue you're having):

  • include = FALSE -- this simply says to go ahead and run the chunk, but don't include it in the output. If an object gets created in that chunk, it can be referenced in a later chunk fine. And, if there is an error in the code when that chunk is knitted, it can halt the knitting process. (This is different from eval = FALSE, which doesn't actually execute the code in the chunk at all)

  • cache = FALSE -- this says to re-run the chunk every time the file is knitted, even if the chunk hasn't changed and the objects resulting from it could be available in the cache.

  • comment = NA -- this removes the default "##" that shows in text output from the chunk.

  • warning = FALSE -- when R functions run, they can return messages, warnings, and errors. You see these in your console pretty often when loading packages (messages, for sure) and running many functions (for instance, there may be a warning that some rows of data were dropped when a plot was being run; or, if a function is not able to run, it will often return an error explaining why). Since warnings and messages do not necessarily halt the code from running, the developer very often is aware of them, has reviewed them, and is totally fine with what they're reporting, but does not want to have them displayed in the final, knitted output. This chunk option simply says, "Don't include any warnings in the output from the chunk." This is different from showing warnings and errors that occur as part of the knitting process itself, though. I think that was why you were eyeing these settings, though. I don't think they're related.

  • message = FALSE -- See the note above. This is just about whether the chunk output should include messages that were generated as part of the code execution—not messages that are part of the knitting process.

I hope this helps a bit. It doesn't get to what the root of the issue you're having is, but, hopefully, at least removes one vector of pursuit in getting there!


Thanks a lot!

Here's the chunk:

```{r out.width='49%', fig.show='hold'}
knitr::include_graphics(c("images/CXR.jpg", "images/CXR.jpg"))

And the message:

Quitting from lines 181-182 (Testing.Rmd) 
Error in loadNamespace(name) : there is no package called 'showtext'


Oh, wow. That's odd!

The error message is a pretty straightforward "you don't have a package installed that is needed," which is generally remedied with a one-time install.packages() call. What's weird, though, is that I don't see exactly why that would be needed.

There is a fig.showtext chunk option (described in Yihui's documentation on chunk options), and that does rely on the showtext package. What's odd is that you're not using that option!

One option would be to install the showtext package and confirm that it installs and is able to be loaded (it's a "suggests" package for knitr). It may be that it's not getting loaded on your machine and, if it was there, the issue would go away.

Another thing to try would be to remove fig.show='hold' from the chunk options and see if the issue goes away then. That would at least hone in on that option being the issue (but I'm not clear on how fig.show and fig.showtext might be related). It could also be related to the include_graphics() function, which is a knitr function. But, again, if showtext was required to use the function, then it shouldn't be just a "suggests" package for knitr.


Well, I installed the "showtext" package, it now runs fine, and the error message does not occur.

:slight_smile: odd


1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.