Code error in Section 12.5.1 mlr::resample
Hello, I am currently running through the code in the book and receiving the following error when running mlr::resample(task = task, learner = learner, resampling = resampling ) :
Error in if (!is.null(resampling$task_row_hash) && resampling$task_row_hash != : missing value where TRUE/FALSE needed
I am not sure where the issue is arising, but it doesn't appear that resampling$task_row_hash is storing properly.
Here is the code I've run (from the book) that is generating the error, as well as some outputs for troubleshooting under the "Check for expected values from troubleshooting". Note that I ran just the book code to start, which generated the same error.
# 1. create task
task = mlr3spatiotempcv::as_task_classif_st(
mlr3::as_data_backend(lsl),
target = "lslpts",
id = "ecuador_lsl",
positive = "TRUE",
coordinate_names = c("x", "y"),
crs = "EPSG:32717",
coords_as_features = FALSE
)
# 2. Set up learner
learner = mlr3::lrn("classif.log_reg", predict_type = "prob")
# 3. Set up resampling
resampling = mlr3::rsmp("repeated_spcv_coords", folds = 5, repeats = 100)
# Check for expected values between resampling and task
task$row_ids # 1-350
resampling$is_instantiated # [1] FALSE
resampling$instantiate(task)
resampling$is_instantiated # [1] TRUE
task$hash # [1] "48ec36253896ff33"
resampling$task_hash # [1] "48ec36253896ff33"
resampling$task_hash == task$hash # [1] TRUE
task$row_hash # [1] "8ce098287dbf2050"
resampling$task_row_hash # NA
resampling$task_nrow # 350
resampling$task_row_hash == task$row_hash # NA
# reduce verbosity
lgr::get_logger("mlr3")$set_threshold("warn")
# Now run resampling
rr_spcv_glm = mlr3::resample(
task = task,
learner = learner,
resampling = resampling)
It appears that the resampling$task_row_hash is not inheriting from task. Any help would be appreciated!
Adding this if it is of any use:
Geocompr packages installed using
install.packages("remotes")
install.packages("geocompkg",
repos = c("https://geocompr.r-universe.dev",
"https://cloud.r-project.org"),
dependencies = TRUE, force = TRUE)
R Session Info:
─ Session info ─────────────────────────────────────────────────────────────────────────
setting value
version R version 4.5.1 (2025-06-13)
os macOS Sequoia 15.5
system aarch64, darwin20
ui RStudio
language (EN)
collate en_US.UTF-8
ctype en_US.UTF-8
tz America/Los_Angeles
date 2025-06-27
rstudio 2024.12.0+467 Kousa Dogwood (desktop)
pandoc NA
quarto 1.5.57 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/quart
Thanks again!
That is useful, thanks @dustin-duncan. I'm not sure what the issue is or how to debug it, hoping @jannes-m or @Nowosad will have more idea than me.
Hi @dustin-duncan -- thanks for opening the issue. I think this is a new problem related with the release of mlr3 version 1.0.0 (https://cran.r-project.org/package=mlr3). I can reproduce it and now I try to find a solution to it...
This issue propagates to mlr3spatiotempcv -- see https://cloud.r-project.org/web/checks/check_results_mlr3spatiotempcv.html.
I assume that it should be fixed on the mlr3 part, I am just unsure if it should be mlr3 or mlr3spatiotempcv. @pat-s -- could you help me here? Should I report this problem somewhere?
Yes, {mlr3spatiotempcv} needs an update after some breaking changes in {mlr3}. It is on my list 🙂️