Why my code executes with when I run each line but fails when I use build in a bookdown?


#1

I have an error I don’t know how to reproduce here.
I have a simple filter statement like: `data <- data %>% filter(v1==35). If I run the code, it works properly.
When I use build in a bookdown project, I get the following message:

“Quitting from lines 1235-1248 (lab-notes.Rmd)
Error in filter_impl(.data, quo) :
Evaluation error: object ‘UF’ not found.”

I’ve been working on this project for a while. It is the first time I have this problem. What makes it even more strange is that I have a couple of filter statements before this one that works just fine.

The problem is not specific to filter, though. I used old cold style data[data$v1==35] to skip the problem since I have a hard deadline coming up, but then I get another error message in a mutate statement.


#2

usually these types of problems can be traced back to a couple things, either the cache or the local environment. I would start by clearing the knitr cache, under Knitr > Clear Knitr Cache. If that doesn’t work, restart R, run rm=ls() to clear the environment and then start running line by line to see if you can narrow down where the problem starts. Pay close attention to when packages are loaded, and if there are any name conflicts.


#3

Is it possible that you have an object, UF, that’s in your active environment, but not in the actual bookdown project?


#4

Many thanks! I realized that my message was not that clear because I copied and pasted the error message. v1 in my example was my UF variable.

The problem disappeared once I merged a development branch into the master and re-build. I don’t know exactly why, though.