r-lib / pkgdown

Generate static html documentation for an R package

Home Page:https://pkgdown.r-lib.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

build_site() fails to render some examples

spsanderson opened this issue · comments

I am not entirely certain as to why this is occurring but when I run the build_site() function on my package some examples no longer render. For example:

library(recipes)
library(dplyr)
library(tidyr)

df <- Titanic |>
 as_tibble() |>
 uncount(n) |>
 mutate(across(everything(), as.factor))

rec_obj <- recipe(Survived ~ ., data = df)

fct_tbl <- fast_classification(
  .data = df,
  .rec_obj = rec_obj,
  .parsnip_eng = c("glm"))

fct_tbl

Gives the following error:

#> Error in dplyr::mutate(mod_fitted_tbl, pred_wflw = internal_make_wflw_predictions(mod_fitted_tbl,     splits_obj)): ℹ In argument: `pred_wflw =
#>   internal_make_wflw_predictions(mod_fitted_tbl, splits_obj)`.
#> Caused by error in `map2()`:
#> ℹ In index: 1.
#> Caused by error in `dplyr::filter()`:
#> ! object 'rec_obj' not found

fct_tbl
#> Error in eval(expr, envir, enclos): object 'fct_tbl' not found

But I can run it fine in the terminal like so:

> library(recipes)
> library(dplyr)
> library(tidyr)
> 
> df <- Titanic |>
+     as_tibble() |>
+     uncount(n) |>
+     mutate(across(everything(), as.factor))
> 
> rec_obj <- recipe(Survived ~ ., data = df)
> 
> fct_tbl <- fast_classification(
+     .data = df,
+     .rec_obj = rec_obj,
+     .parsnip_eng = c("glm"))
> 
> fct_tbl
# A tibble: 1 × 8
  .model_id .parsnip_engine .parsnip_mode  .parsnip_fns model_spec wflw       fitted_wflw pred_wflw
      <int> <chr>           <chr>          <chr>        <list>     <list>     <list>      <list>   
1         1 glm             classification logistic_reg <spec[+]>  <workflow> <workflow>  <tibble> 

Your reprex doesn't run as-is. Where does fast_classification() come from?

library(recipes)
#> Loading required package: dplyr
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
#> 
#> Attaching package: 'recipes'
#> The following object is masked from 'package:stats':
#> 
#>     step
library(dplyr)
library(tidyr)

df <- Titanic |>
  as_tibble() |>
  uncount(n) |>
  mutate(across(everything(), as.factor))

rec_obj <- recipe(Survived ~ ., data = df)

fct_tbl <- fast_classification(
  .data = df,
  .rec_obj = rec_obj,
  .parsnip_eng = c("glm"))
#> Error in fast_classification(.data = df, .rec_obj = rec_obj, .parsnip_eng = c("glm")): could not find function "fast_classification"

fct_tbl
#> Error in eval(expr, envir, enclos): object 'fct_tbl' not found

Created on 2023-12-20 with reprex v2.0.2

This question was also posted here: https://stackoverflow.com/q/77689110.

You need to tell R that, by using library(tidyAML) before using it, or tidyAML::fast_classification when you use it. That's why your example doesn't run.

No, you shouldn't need to specify the package if you have it installed, and I think build_site() does an install in any case. I just cloned the tidyAML master branch and didn't get any error from build_site(). Have you made changes relative to the master branch? If so, I'd try installing first to make sure there are no errors.

Whoops, now I look at the output, I do see the error you reported.

I tried to take a closer look, but I couldn't follow the code you are using. You're doing a lot of tricky things -- suppressing errors, etc. I'd suggest adding a lot of message statements to the problematic function, which appears to be internal_make_wflw_predictions. Get them to print information about the intermediate values, or check that the assumptions you're making are true and print results from them.

I tried a bit of this, but as I said, I couldn't follow your code.

You can save some time by only running

pkgdown::build_reference(topics="fast_classification")

so only that page gets built.

I added this to the function and now it is working:

rec_obj <- workflows::extract_preprocessor(fitted_wflw)