learnr tutorial fails when run with run_tutorial

I have made a package with some learnr tutorials, available at https://github.com/Bio302-UiB/data-handling

The tutorials all work before I build the package, but afterwards one of the tutorials fails when run with learnr::run_tutorial(). It also fails when run from the tutorials tab.

remotes::install_github("Bio302-UiB/data-handling")
> learnr::run_tutorial("text-manipulation", package = "data.handling")

processing file: text-manipulation.Rmd
...

  |................................                |  66%
label: replace-tibble
Quitting from lines 284-288 (text-manipulation.Rmd) 
Error: Problem with `mutate()` input `species`.
x unused argument (string = species)
ℹ Input `species` is `str_replace(string = species, pattern = "_", replacement = " ")`.

The chunk that is failing for learnr is

{r replace-tibble}
diatom_df %>% 
  mutate(species = str_replace(string = species,
                               pattern = "_", 
                               replacement  = " "))

The same tutorial works fine if I open the file from the package and use the blue knit button

usethis::edit_file(system.file("tutorials/text-manipulation/text-manipulation.Rmd", package = "data.handling"))

(Thereafter run_tutorial works, but is presumably using the pre-rendered html)

I don't even know how to start to debug this problem. Any suggestions?

1 Like

I am wondering if there is an odd interaction between your personal R session and running the document.

Can you try running the code below?

learnr::safe({
  learnr::run_tutorial("text-manipulation", package = "data.handling")
})

This should put learnr::run_tutorial() in a clean / fresh background R process. This will isolate the learnr::run_tutorial() call from your local environment (which will behave very similar to the blue knit button or a deployed tutorial.)

Thanks for the suggestion. I tried it and unfortunately I still get the same error.

Some colleagues have also tried the tutorial and get the same error (different versions of Rstudio, Linux and Mac).

Curiously, if I only get the error when I install from github (with either remotes or renv). When I install with the Install and restart button on the build tab in rstudio, everything works fine.

I've had a similar thing happen this week. I made a set of tutorials for a class that I'm teaching and put them into a package. I tested the tutorials locally and they worked perfectly. When the same tutorials are run from the package they fail (the exercise checker isn't seeing the setup stuff)

My students have found the same thing - they can't run the tutorials from the package but are able to run the markdown files and use the tutorials with no issue. I'd be interested if there is a solution to this!

The package is here https://github.com/kate-pyper/MM916ProgrammingExercises and the tutorial is called pivot_longer (although it does happen with other tutorials in the package)

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.