From 42bcf52bbe488911768d308b3b441c22d1a16bb6 Mon Sep 17 00:00:00 2001 From: Gerko Vink Date: Thu, 5 Oct 2023 16:37:28 +0200 Subject: [PATCH 1/2] ampute returns data in its original structure --- R/ampute.R | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/R/ampute.R b/R/ampute.R index b30aeea6e..cd7482af3 100644 --- a/R/ampute.R +++ b/R/ampute.R @@ -208,6 +208,7 @@ ampute <- function(data, prop = 0.5, patterns = NULL, freq = NULL, if (is.null(data)) { stop("Argument data is missing, with no default", call. = FALSE) } + data.in <- data # preserve an original set to inject the NA's in later data <- check.dataform(data) if (anyNA(data)) { stop("Data cannot contain NAs", call. = FALSE) @@ -218,7 +219,7 @@ ampute <- function(data, prop = 0.5, patterns = NULL, freq = NULL, data <- data.frame(data) if (any(vapply(data, Negate(is.numeric), logical(1))) && mech != "MCAR") { data <- as.data.frame(sapply(data, as.numeric)) - warning("Data is made numeric because the calculation of weights requires numeric data", + warning("Data is made numeric internally, because the calculation of weights requires numeric data", call. = FALSE ) } @@ -454,7 +455,7 @@ ampute <- function(data, prop = 0.5, patterns = NULL, freq = NULL, names(patterns.new) <- names(data) names(weights) <- names(data) call <- match.call() - missing.data <- data.frame(missing.data) + data.in[is.na(data.frame(missing.data))] <- NA result <- list( call = call, prop = prop, @@ -466,7 +467,7 @@ ampute <- function(data, prop = 0.5, patterns = NULL, freq = NULL, std = std, type = type, odds = odds, - amp = missing.data, + amp = data.in, cand = P - 1, scores = scores, data = as.data.frame(data) From aa2f538818cd5133470becc05d7bfd75aeb533a2 Mon Sep 17 00:00:00 2001 From: Gerko Vink Date: Thu, 5 Oct 2023 16:37:51 +0200 Subject: [PATCH 2/2] rephrase the tested warning expectation --- tests/testthat/test-ampute.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-ampute.R b/tests/testthat/test-ampute.R index 159e794cc..761909ba8 100644 --- a/tests/testthat/test-ampute.R +++ b/tests/testthat/test-ampute.R @@ -99,7 +99,7 @@ test_that("function works around unusual arguments", { # when data is categorical and mech != mcar, warning is expected expect_warning( ampute(data = nasty.data), - "Data is made numeric because the calculation of weights requires numeric data" + "Data is made numeric internally, because the calculation of weights requires numeric data" ) # when data is categorical and mech = mcar, function can continue expect_warning(ampute(data = nasty.data, mech = "MCAR"), NA)