Use global option for verbosity in R package and add tests.

This commit is contained in:
Ryan Curtin
2024-05-14 23:02:33 -04:00
parent a1f444ee5b
commit d1cc4e2fc4
2 changed files with 36 additions and 1 deletions
@@ -335,3 +335,25 @@ test_that("TestReallyNotVerbose", {
build_model=TRUE,
verbose=FALSE))
})
# Make sure that the mlpack verbose global option does anything at all.
test_that("TestGlobalVerbose", {
options(mlpack.verbose = TRUE)
expect_output(test_r_binding(4.0, 12, "hello",
build_model=TRUE))
})
# Test that we get no output when the global verbose option is set to false.
test_that("TestGlobalNotVerbose", {
options(mlpack.verbose = FALSE)
expect_silent(test_r_binding(4.0, 12, "hello",
build_model=TRUE))
})
# Test that we can override the global verbose option.
test_that("TestGlobalVerboseOverride", {
options(mlpack.verbose = TRUE)
expect_silent(test_r_binding(4.0, 12, "hello",
build_model=TRUE,
verbose=FALSE))
})
+14 -1
View File
@@ -30,9 +30,22 @@ void PrintInputParam(util::ParamData& d,
{
MLPACK_COUT_STREAM << d.name;
if (std::is_same<T, bool>::value)
MLPACK_COUT_STREAM << "=FALSE";
{
if (d.name == "verbose")
{
// Make sure that we use the global verbose option for the mlpack package
// as the default.
MLPACK_COUT_STREAM << "=getOption(\"mlpack.verbose\", FALSE)";
}
else
{
MLPACK_COUT_STREAM << "=FALSE";
}
}
else if (!d.required)
{
MLPACK_COUT_STREAM << "=NA";
}
}
} // namespace r