Unverified Commit ab788291 authored by James Lamb's avatar James Lamb Committed by GitHub
Browse files

[R-package] fix handling of duplicate parameters (fixes #4521) (#4914)

* [R-package] fix handling of duplicate parameters (fixes #4521)

* add gsub stuff back in for now
parent f9053abb
......@@ -25,20 +25,19 @@ lgb.params2str <- function(params) {
stop("params must be a list")
}
# Split parameter names
names(params) <- gsub("\\.", "_", names(params))
param_names <- names(params)
ret <- list()
# Perform key value join
for (key in names(params)) {
for (i in seq_along(params)) {
# If a parameter has multiple values, join those values together with commas.
# trimws() is necessary because format() will pad to make strings the same width
val <- paste0(
trimws(
format(
x = params[[key]]
x = unname(params[[i]])
, scientific = FALSE
)
)
......@@ -47,7 +46,7 @@ lgb.params2str <- function(params) {
if (nchar(val) <= 0L) next # Skip join
# Join key value
pair <- paste0(c(key, val), collapse = "=")
pair <- paste0(c(param_names[[i]], val), collapse = "=")
ret <- c(ret, pair)
}
......
......@@ -26,6 +26,17 @@ test_that("lgb.params2str() works as expected for a key in params with multiple
)
})
test_that("lgb.params2str() passes through duplicated params", {
out_str <- lgb.params2str(
params = list(
objective = "regression"
, bagging_fraction = 0.8
, bagging_fraction = 0.5
)
)
expect_equal(out_str, "objective=regression bagging_fraction=0.8 bagging_fraction=0.5")
})
context("lgb.check.eval")
test_that("lgb.check.eval works as expected with no metric", {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment