Can't load package in vignette, etc. when using renv for isolation

Hello,
This is kind of a weirdly circular scenario, and maybe the answer is just "sorry, you can't do that" but I wanted to see what folks thought.

I am using renv in a package that I'm developing, in order to isolate the environment and make sure all the developers are working with the same versions of the dependencies. Overall, it's working great. Yee haw.

But I just stumbled onto this weird issue: when I try to run the vignettes interactively, they die on the first chunk where I load my library (with library(rbabylon), which is my package). It just errors with Error in library(rbabylon) : there is no package called ‘rbabylon’ because, of course, there is no rbabylon installed in renv/library/....

Now, in real life, I know what the problem is and I can just run devtools::load_all() or whatever and skip this chunk and run the rest of the vignette interactively. But then I feel like I want to put a big comment in an include=F block above it that tells other developers about this issue so that they don't get weird when they see that message... and then that feels hacky... and so I'm just wondering if anyone else has run into this and if there is a recommended fix.

Sidenote: I ran into a similar thing with some scripts I have in data-raw that generate my test data, although for those I just replaced library(rbabylon) with devtools::load_all(). It still felt a little hacky, but it worked fine. For some reason doing it in the vignettes feels like a step too far though.

Any thoughts and ideas are much appreciated!

Would it suffice to also install your package into your project library before trying to run vignette code? (This is effectively what R does as well when building vignettes for a package, since it relies on an installed version of your package being available in order to run the code chunks within.)

The other option here would be to have a setup chunk with something like:

```{r setup, include=FALSE}
# NOTE: if running chunks interactively we need to load the package first
if (interactive()) {
  devtools::load_all()
}
```

that at least tells developers that if they want to edit and run the vignette interactively, they'll need to prep their environment first. Setting include=FALSE should ensure that the chunk itself isn't included in the generated vignette, and the interactive() check means R will ignore it when building the package for release.

Thanks Kevin. That works I guess. It's more or less what I had done before that felt "hacky" but somehow adding the if(interactive()) block makes it feel more legit.

I also wasn't sure if this was still going to make the next block (where I call library(rbabylon)) error, but it works fine.

> library(rbabylon)
Error in library(rbabylon) : there is no package called ‘rbabylon’
> devtools::load_all()
Loading rbabylon
> library(rbabylon)
> 

I don't fully understand what devtools::load_all() is doing, beyond that it " roughly simulates what happens when a package is installed and loaded with library() ." But, whatever it's doing, it allows the next library() call to succeed. I guess it's probably more about what library() is doing, now that I think about it...

Thanks again!