Search code examples
htmlrrnotebook

r notebook html output has incorrect order and strange error


I am having a strange issue with an R notebook file. I believe the error may have started when I converted to a markdown file and then back to notebook. In my R script, I have no issues and everything is in order. When I knit the notebook to HTML, a chunk of code appears in the same spot every time that is not in the correct order (this chunk of code is later in the document) and I get a strange output:

<!-- rnb-text-end -->


<!-- rnb-chunk-begin -->


<!-- rnb-source-begin eyJkYXRhIjoiYGBgclxuI25ldyBhdmVyYWdlIGFtb3VudCBvZiB0aWNrZXRzXG5tZWFuKHRpY2tldHMpXG4jMC44XG5ubG9vcD0xMDAwMDBcbnNhbXBsZW1lYW49MTpubG9vcFxuZm9yKGlsb29wIGluIDE6bmxvb3ApIHtcbiAgeD1zYW1wbGUoMDozLDIwLHJlcGxhY2UgPSBUUlVFLHByPWMoLjY1LC4yNywuMDYsLjAyKSlcbiAgc2FtcGxlbWVhbltpbG9vcF09bWVhbih4KVxufVxuaGlzdChzYW1wbGVtZWFuLCBicj0xMDApXG4jd2hhdCdzIHByb2Igb2YgZ2V0dGluZyB0aGlzIG9yIG1vcmUgdGhhbiAwLjggKGN1cnJlbnQgYXZlcmFnZT8pXG5zdW0oc2FtcGxlbWVhbj49MC44KS9ubG9vcFxuYGBgIn0= -->

After this it changes all my formatting, headers, and codes to inline text. My entire document is not affected, however I cannot find a reason as to why it suddenly works again. If I go into the R file and cut and paste the R code that shows up where it is out of place, it seems to work. However, another code chunk just takes its place.

I have included screenshots since it is easier to visualize I am sure. I have also looked into this solution about the spacing of my chunk name but I don't think that's what is causing the issue: https://community.rstudio.com/t/html-notebook-error-in-rmarkdown/89440

TLDR: out of order code in strange output that only impacts part of HTML notebook. I am happy to provide more code or screenshots if that is helpful to anyone who may understand this issue better.

r scriptnotebook output


Solution

  • While this may not be a great solution, copying and pasting my entire code into a new document seemed to be a good enough work around for now! The document looks like it normally should now when I knit it.