From 6f6b85d81b2c5249d155a12f35306810722359a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20S=C3=B8rensen?= Date: Thu, 14 Mar 2024 16:21:54 +0100 Subject: [PATCH] Solving CRAN issue (#403) * fixing the issue * styling --- DESCRIPTION | 2 +- NEWS.md | 5 +++++ R/compute_mallows_sequentially.R | 7 +++++++ cran-comments.md | 2 +- .../compute_mallows_sequentially_example.R | 2 +- man/compute_mallows_sequentially.Rd | 2 +- .../test-compute_mallows_sequentially.R | 21 +++++++++++++++++++ work-docs/docker.sh | 2 +- 8 files changed, 38 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ced95598..e73e242b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: BayesMallows Type: Package Title: Bayesian Preference Learning with the Mallows Rank Model -Version: 2.1.0 +Version: 2.1.1 Authors@R: c(person("Oystein", "Sorensen", email = "oystein.sorensen.1985@gmail.com", role = c("aut", "cre"), diff --git a/NEWS.md b/NEWS.md index 2aeacc83..49bc2e65 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# BayesMallows 2.1.1 + +* Fixed gcc-UBSAN issue happening when compute_mallows_sequentially() is run + without user IDs specified. + # BayesMallows 2.1.0 * The SMC method update_mallows() now supports pairwise preferences, both new diff --git a/R/compute_mallows_sequentially.R b/R/compute_mallows_sequentially.R index d6041d1e..1f334abb 100644 --- a/R/compute_mallows_sequentially.R +++ b/R/compute_mallows_sequentially.R @@ -54,6 +54,13 @@ compute_mallows_sequentially <- function( if (!is.list(data) | !all(vapply(data, inherits, logical(1), "BayesMallowsData"))) { stop("data must be a list of BayesMallowsData objects.") } + if (any( + vapply(data, function(x) { + is.null(x$user_ids) || length(x$user_ids) == 0 + }, logical(1)) + )) { + stop("User IDs must be set.") + } pfun_values <- extract_pfun_values(model_options$metric, data[[1]]$n_items, pfun_estimate) alpha_init <- sample(initial_values$alpha, smc_options$n_particles, replace = TRUE) rho_init <- initial_values$rho[, sample(ncol(initial_values$rho), smc_options$n_particles, replace = TRUE)] diff --git a/cran-comments.md b/cran-comments.md index 8d398afa..a671e155 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,6 +1,6 @@ ## Resubmission Note -This is a resubmission, fixing a failing unit test on noLD and containing a large number of new features. +This is a resubmission, fixing the gcc-UBSAN error reported on CRAN. ## Test Environments diff --git a/inst/examples/compute_mallows_sequentially_example.R b/inst/examples/compute_mallows_sequentially_example.R index 39e0ca54..19f2dcd2 100644 --- a/inst/examples/compute_mallows_sequentially_example.R +++ b/inst/examples/compute_mallows_sequentially_example.R @@ -1,7 +1,7 @@ # Observe one ranking at each of 12 timepoints library(ggplot2) data <- lapply(seq_len(nrow(potato_visual)), function(i) { - setup_rank_data(potato_visual[i, ]) + setup_rank_data(potato_visual[i, ], user_ids = i) }) initial_values <- sample_prior( diff --git a/man/compute_mallows_sequentially.Rd b/man/compute_mallows_sequentially.Rd index d5d48c29..5b294d14 100644 --- a/man/compute_mallows_sequentially.Rd +++ b/man/compute_mallows_sequentially.Rd @@ -61,7 +61,7 @@ for some workarounds. # Observe one ranking at each of 12 timepoints library(ggplot2) data <- lapply(seq_len(nrow(potato_visual)), function(i) { - setup_rank_data(potato_visual[i, ]) + setup_rank_data(potato_visual[i, ], user_ids = i) }) initial_values <- sample_prior( diff --git a/tests/testthat/test-compute_mallows_sequentially.R b/tests/testthat/test-compute_mallows_sequentially.R index 771a929e..328ad7e7 100644 --- a/tests/testthat/test-compute_mallows_sequentially.R +++ b/tests/testthat/test-compute_mallows_sequentially.R @@ -72,3 +72,24 @@ test_that("compute_mallows_sequentially works with partial rankings", { ) ) }) + +test_that("compute_mallows_sequentially validates input", { + set.seed(345) + data <- lapply(seq_len(nrow(potato_visual)), function(i) { + setup_rank_data(potato_visual[i, ]) + }) + + initial_values <- sample_prior( + n = 200, n_items = 20, + priors = set_priors(gamma = 3, lambda = .1) + ) + + expect_error( + compute_mallows_sequentially( + data = data, + initial_values = initial_values, + smc_options = set_smc_options(n_particles = 200, mcmc_steps = 20) + ), + "User IDs must be set." + ) +}) diff --git a/work-docs/docker.sh b/work-docs/docker.sh index b09e6ddd..be345f21 100644 --- a/work-docs/docker.sh +++ b/work-docs/docker.sh @@ -1,5 +1,5 @@ # On M1 Mac: -docker run -v "$(pwd)":"/opt/$(basename $(pwd))" --platform linux/amd64 -it --cap-add=SYS_PTRACE rocker/r-devel-san /bin/bash +docker run -v "$(pwd)":"/opt/$(basename $(pwd))" --platform linux/amd64 -it --cap-add=SYS_PTRACE rocker/r-devel-san-oyss /bin/bash # On Intel Mac: docker run -v "$(pwd)":"/opt/$(basename $(pwd))" -it --cap-add=SYS_PTRACE rocker/r-devel-san /bin/bash