diff --git a/h2o-r/h2o-package/R/kvstore.R b/h2o-r/h2o-package/R/kvstore.R index 1d721cfc38c6..dfccbb2699ba 100644 --- a/h2o-r/h2o-package/R/kvstore.R +++ b/h2o-r/h2o-package/R/kvstore.R @@ -47,12 +47,12 @@ h2o.ls <- function() { #' Remove All Objects on the H2O Cluster #' #' Removes the data from the h2o cluster, but does not remove the local references. -#' Retains frames and vectors specified in retained_elements argument. -#' Retained keys must be keys of models and frames only. For models retained, training and validation frames are retained as well. +#' Retains models, frames and vectors specified in retained_elements argument. +#' Retained elements must be instances/ids of models and frames only. For models retained, training and validation frames are retained as well. #' Cross validation models of a retained model are NOT retained automatically, those must be specified explicitely. #' #' @param timeout_secs Timeout in seconds. Default is no timeout. -#' @param retained_elements Frames and vectors to be retained. Other keys provided are ignored. +#' @param retained_elements Instances or ids of models and frames to be retained. Combination of instances and ids in the same list is also a valid input. #' @seealso \code{\link{h2o.rm}} #' @examples #' \dontrun{ @@ -76,6 +76,10 @@ h2o.removeAll <- function(timeout_secs=0, retained_elements = c()) { retained_keys <- append(retained_keys, element@model_id) } else if (is.H2OFrame(element)) { retained_keys <- append(retained_keys, h2o.getId(element)) + } else if( is.character(element) ) { + retained_keys <- append(retained_keys, element) + } else { + stop("The 'retained_elements' variable must be either an instance of H2OModel/H2OFrame or an id of H2OModel/H2OFrame.") } } @@ -122,7 +126,7 @@ h2o.rm <- function(ids, cascade=TRUE) { } else if( is.character(xi) ) { .h2o.__remoteSend(paste0(.h2o.__DKV, "/",xi), method = "DELETE", .params=list(cascade=cascade)) } else { - stop("input to h2o.rm must be a Keyed instance (e.g. H2OFrame, H2OModel) or character") + stop("Input to h2o.rm must be either an instance of H2OModel/H2OFrame or a character") } } diff --git a/h2o-r/tests/testdir_misc/runit_retain.R b/h2o-r/tests/testdir_misc/runit_retain.R index 0d8d2653e9ac..ef66e4332cbf 100644 --- a/h2o-r/tests/testdir_misc/runit_retain.R +++ b/h2o-r/tests/testdir_misc/runit_retain.R @@ -19,9 +19,17 @@ test.h2o.retain <- function() { h2o.removeAll(retained_elements = c(data, model)) expect_false(is.null(h2o.getFrame(h2o.getId(data)))) expect_false(is.null(h2o.getModel(model@model_id))) - + + h2o.removeAll(retained_elements = c(h2o.getId(data), model@model_id)) + expect_false(is.null(h2o.getFrame(h2o.getId(data)))) + expect_false(is.null(h2o.getModel(model@model_id))) + + h2o.removeAll(retained_elements = c(data, model@model_id)) + expect_false(is.null(h2o.getFrame(h2o.getId(data)))) + expect_false(is.null(h2o.getModel(model@model_id))) + h2o.removeAll() - + expect_equal(length(h2o.ls()$key), 0) } doTest("Test h2o.retain", test.h2o.retain)