R Markdown error messages

rmarkdown

#1

So, this is a problem I’ve had before (read: on the regular), and happily work around, but that I thought might be helpful to others.

When I knit an R Markdown document and there are errors, the Line number doesn’t match up with the line numbers in the document.

e.g.

Double-clicking on the error message just brings you to the line number stated, so I usually end up searching for the text that shows up in the error message

I used to basically count lines within my code chunks, but ever since my discovery of r emo::ji(), my use of inline code (and errors therein :flushed:) has kind of skyrocketed.

I have no idea what the internals look like for this, and, thus, have no understanding of technical feasibility, but I’m curious if there have been any ideas about how this might be done differently for R Markdown.

My first thought (or second, rather, the first would be not to make mistakes in my code) is just to do away with line numbers all together (I’ve spent more time trying to discover mistakes in a particular line of text than I should probably admit), but that seems like throwing the baby out with the bathwater.
:baby::bathtub:⇨:wastebasket:

Don’t think it’s relevant, but just in case, setup info:

  • RStudio Version 1.1.383
  • R version 3.4.2
  • rmarkdown 1.6.0

#2

I am so glad that I am not the only one that has this error!!! It has always driven me crazy :exploding_head:

This is the same exact workaround that I use to find my errors, so I’m very interested in what everyone else has to say.

Edit: @mara Just out of curiosity, what kind of project are you working on that is using Goodreads?


#3

Can you share an R Markdown document that exhibits this kind of issue? I believe RStudio retrieves these errors from knitr, which will typically output (e.g. for a chunk which has some error):

Quitting from lines 5-10 (example.Rmd) 
Error in eval(expr, envir, enclos) : object 'a' not found

In other words, we get a range from which the error occurred, but not the actual line. Of course, this doesn’t seem to be the case in your document so I’m curious if something else is afoot here.


#4

This one’s scraping descriptions (mainly taken from a post by Giora Simonchi, here:


)

But, my part 1 is here:


#5

Is this some sort of trick question wherein you went in and magically fixed everything? Because now all my Rmd code chunk ones are totally giving me the right line numbers for errors! And, in the fresh ones I cooked up, if I fail to finish an inline bit of R code it’s just printing it as text…

To be updated once I can successfully break things again!


#6

@mara That’s fascinating! I had never even thought about the distribution
of Children’s books between male & female. Can’t wait to read Part 2!


#7

@mara Noticed you put part 2 on your blog, it was great! It tempts me to get a Goodreads account just to have a fun project :grin: