diff --git a/NEWS.md b/NEWS.md index 92eced80d372887b0debaeae13540618bc06dce4..267a0f56344b256b250628cf3b87adee33be3f85 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,7 @@ <!-- News Style-guide: https://style.tidyverse.org/news.html --> * Moved to new repository: [AGSeifert/RFSurrogates](https://github.com/AGSeifert/RFSurrogates) +* Fixed `mean.index()` bug which caused the return value to be of incorrect length in some cases (#4). --- diff --git a/R/meanAdjAgree.R b/R/meanAdjAgree.R index f9a67a1c687f552826ebec9e5d7e2e2804295a45..d228d667bca74b2f37a806849f7600d300cddde2 100644 --- a/R/meanAdjAgree.R +++ b/R/meanAdjAgree.R @@ -67,7 +67,7 @@ mean.index <- function(i, list.res, index.variables) { list <- list.res[which(names(list.res) == index.variables[i])] mean.list <- round(Reduce("+", list) / length(list), 2) if (length(mean.list) > 0) { - mean.list[index.variables[i]] <- NA + mean.list[i] <- NA return(mean.list) } else { return(rep(NA, length(index.variables))) diff --git a/TROUBLESHOOTING.md b/TROUBLESHOOTING.md new file mode 100644 index 0000000000000000000000000000000000000000..4fa99a5150d822168413a1b487349462f2998682 --- /dev/null +++ b/TROUBLESHOOTING.md @@ -0,0 +1,23 @@ +# Troubleshooting common issues + +## `Error in var.relations: allvariables do not contain the candidate variables` + +This guard clause is intended to catch cases where you are attempting to look at candidate variables not included in the data set. +Firstly, make sure that your `candidates` argument only contains variables present in your indepedent variables `x`: + +```r +all(candidates %in% colnames(x)) # Must evaluate to TRUE +``` + +However, if you are using a data set with number-like feature identifiers, these will be automatically coerced into `X<number>` when the data frame is created, causing this mismatch. +To fix this, change your argument by adding `paste0("X", candidates)`. +Make sure to do the same for the `variables` argument too. + +## `var.select.smd` is stuck at `Growing trees.. Progress` + +The output `Growing trees..` is made by `ranger` while a large forest is being built. The main part of the function however does not emit any progress messages, causing it to appear stalled. +You can verify the function is still running by checking your CPU usage. +This issue is especially relevant for large data sets. + +This should be improved since the rework (Version 0.3.0). +It is still recommended to use a high performance computer with large amounts of RAM for larger data sets. diff --git a/tests/testthat/test-meanAdjAgree_index.mean.R b/tests/testthat/test-meanAdjAgree_index.mean.R new file mode 100644 index 0000000000000000000000000000000000000000..b3e6dcb3f5409072475d3823e08304425bd6747f --- /dev/null +++ b/tests/testthat/test-meanAdjAgree_index.mean.R @@ -0,0 +1,28 @@ +test_that("mean.index always returns a numeric vector of length(index.variables)", { + list.res <- rlist::list.flatten( + list( + list(`1` = c(0.0, 0.5, 0.5, 0.5)), + list(`1` = c(0.0, 0.6, 0.7, 0.8)), + list(`5` = c(0.4, 0.0, 0.4, 0.4)), + list(`99` = c(0.1, 0.2, 0.1, 0.2)), + list(`100` = c(0.9, 0.3, 0.0, 0.9)), + list(`10000` = c(0.7, 0.8, 0.9, 0.0)), + list(`5` = c(0.3, 0.0, 0.5, 0.6), `100` = c(0.7, 0.6, 0.0, 0.9)) + ) + ) + index.variables = c(1, 5, 100, 10000) + + # 1 would not go out of bounds, thus should always pass + testthat::expect_length(mean.index(1, list.res, index.variables), length(index.variables)) + testthat::expect_length(mean.index(2, list.res, index.variables), length(index.variables)) + testthat::expect_length(mean.index(3, list.res, index.variables), length(index.variables)) + testthat::expect_length(mean.index(4, list.res, index.variables), length(index.variables)) + # 5 is out of bounds of index.variables, returning only NA of correct length + testthat::expect_length(mean.index(5, list.res, index.variables), length(index.variables)) +}) + +test_that("mean.index returns NA vector when i is out of bounds of index.variables", { + list.res <- list() + index.variables = 1:4 + testthat::expect_equal(mean.index(5, list.res, index.variables), rep(NA, length(index.variables))) +}) diff --git a/tests/testthat/test-testthat.R b/tests/testthat/test-testthat.R deleted file mode 100644 index c5c1b4a5caf72d36637699c96214c72191d22fff..0000000000000000000000000000000000000000 --- a/tests/testthat/test-testthat.R +++ /dev/null @@ -1,3 +0,0 @@ -test_that("testthat works", { - expect_equal(2 * 2, 4) -})