I have the following as an example in two files
@examples
x <- mtcars$mpg
some_func_here(x)
The some_func_here(x) is failing because it says that x is not found...
Here are the two pages where the example fails: bootstrap_p_augment AND bootstrap_p_vec
Here are examples where x the same x works ci_hi
So I am not understanding why it is failing, nor do I even know where to start looking.
As discussed in the comments, there is a bug in the
bootstrap_p_vecfunction. It has an argument.x, but it checked whetherxwas numeric. See https://github.com/spsanderson/TidyDensity/blob/a101d7568fbae0a883e7dfaf960236f98cb59fe8/R/vec-bootstrap-p.R#L34 .In functions in packages, the search order for variables is as follows:
xdefined there so this also fails.xthere.xin the global environment, so you didn't get the error you should have got in normal runs.If you had named the global variable
xnewand didn't have some other variable calledxlying around, you would have got the error even in normal runs.When
pkgdown::build_site()runs your code, it doesn't follow the same rules. It sets up a fake global environment, and never puts that in the search list. Effectively this means it skips the last step above, so it never findsx. In my opinion, this is a better way to do variable searches, because users sometimes have total junk in their global environment, and you don't want a typo to find that and work with it. You want typos to cause immediate failures.If you ran
R CMD checkon your package, you should have seen a warning thatbootstrap_p_vecuses the globalx. Except you won't see that, because you have suppressed this warning by declaringxwithin00_global_variables.R, effectively saying that everything is okay (even though it wasn't).Unfortunately, code in the tidyverse gets a huge number of false positive warnings about globals, so tidyverse code almost has no choice but to suppress this error. They should have stuck with standard evaluation, and then you wouldn't have this insidious bug in your code.