Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@

* Fix usage of precompiled headers; remove cotire (#3635).

* Fix non-working `verbose` option for R bindings (#3691).
* Fix non-working `verbose` option for R bindings (#3691), and add global
`mlpack.verbose` option (#3706).

### mlpack 4.3.0
###### 2023-11-27
Expand Down
15 changes: 14 additions & 1 deletion src/mlpack/bindings/R/default_param_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,22 @@ std::string DefaultParamImpl(
{
std::ostringstream oss;
if (std::is_same<T, bool>::value)
oss << "FALSE";
{
// If this is the verbose option, print the default that uses the global
// package option.
if (data.name == "verbose")
{
oss << "getOption(\"mlpack.verbose\", FALSE)";
}
else
{
oss << "FALSE";
}
}
else
{
oss << MLPACK_ANY_CAST<T>(data.value);
}

return oss.str();
}
Expand Down
14 changes: 0 additions & 14 deletions src/mlpack/bindings/R/mlpack/src/r_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,20 +363,6 @@ List IO_GetParamMatWithInfo(SEXP params, const std::string& paramName)
Rcpp::Named("Data") = std::move(m));
}

// Enable verbose output.
// [[Rcpp::export]]
void EnableVerbose()
{
Log::Info.ignoreInput = false;
}

// Disable verbose output.
// [[Rcpp::export]]
void DisableVerbose()
{
Log::Info.ignoreInput = true;
}

// Reset the state of all timers.
// [[Rcpp::export]]
void ResetTimers()
Expand Down
22 changes: 22 additions & 0 deletions src/mlpack/bindings/R/mlpack/tests/testthat/test-R_binding.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
11 changes: 10 additions & 1 deletion src/mlpack/bindings/R/print_doc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,16 @@ void PrintDoc(util::ParamData& d,
}
else if (d.cppType == "bool")
{
oss << (MLPACK_ANY_CAST<bool>(d.value) ? "TRUE" : "FALSE");
// If the option is `verbose`, be sure to print the use of the global
// mlpack package option as a default.
if (d.name == "verbose")
{
oss << "getOption(\"mlpack.verbose\", FALSE)";
}
else
{
oss << (MLPACK_ANY_CAST<bool>(d.value) ? "TRUE" : "FALSE");
}
}
oss << "\"";
}
Expand Down
15 changes: 14 additions & 1 deletion src/mlpack/bindings/R/print_input_param.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down