Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R-package] Update remaining internal function calls to use keyword arguments #3617

Merged
merged 7 commits into from
Dec 1, 2020
2 changes: 1 addition & 1 deletion R-package/R/callback.R
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ cb.early.stop <- function(stopping_rounds, first_metric_only = FALSE, verbose =

# Check for empty evaluation
if (is.null(eval_len)) {
init(env)
init(env = env)
}

# Store iteration
Expand Down
40 changes: 22 additions & 18 deletions R-package/R/lgb.Booster.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ Booster <- R6::R6Class(
finalize = function() {

# Check the need for freeing handle
if (!lgb.is.null.handle(private$handle)) {
if (!lgb.is.null.handle(x = private$handle)) {

# Freeing up handle
lgb.call("LGBM_BoosterFree_R", ret = NULL, private$handle)
lgb.call(fun_name = "LGBM_BoosterFree_R", ret = NULL, private$handle)
private$handle <- NULL

}
Expand Down Expand Up @@ -47,7 +47,7 @@ Booster <- R6::R6Class(
params_str <- lgb.params2str(params = params)
# Store booster handle
handle <- lgb.call(
"LGBM_BoosterCreate_R"
fun_name = "LGBM_BoosterCreate_R"
, ret = handle
, train_set_handle
, params_str
Expand All @@ -64,7 +64,7 @@ Booster <- R6::R6Class(

# Merge booster
lgb.call(
"LGBM_BoosterMerge_R"
fun_name = "LGBM_BoosterMerge_R"
, ret = NULL
, handle
, private$init_predictor$.__enclos_env__$private$handle
Expand All @@ -86,7 +86,7 @@ Booster <- R6::R6Class(
handle <- lgb.call(
fun_name = "LGBM_BoosterCreateFromModelfile_R"
, ret = handle
, lgb.c_str(modelfile)
, lgb.c_str(x = modelfile)
)

} else if (!is.null(model_str)) {
Expand All @@ -100,7 +100,7 @@ Booster <- R6::R6Class(
handle <- lgb.call(
fun_name = "LGBM_BoosterLoadModelFromString_R"
, ret = handle
, lgb.c_str(model_str)
, lgb.c_str(x = model_str)
)

} else {
Expand All @@ -116,7 +116,7 @@ Booster <- R6::R6Class(
})

# Check whether the handle was created properly if it was not stopped earlier by a stop call
if (isTRUE(lgb.is.null.handle(handle))) {
if (isTRUE(lgb.is.null.handle(x = handle))) {

stop("lgb.Booster: cannot create Booster handle")

Expand Down Expand Up @@ -168,7 +168,7 @@ Booster <- R6::R6Class(

# Add validation data to booster
lgb.call(
"LGBM_BoosterAddValidData_R"
fun_name = "LGBM_BoosterAddValidData_R"
, ret = NULL
, private$handle
, data$.__enclos_env__$private$get_handle()
Expand All @@ -193,7 +193,7 @@ Booster <- R6::R6Class(

# Reset parameters
lgb.call(
"LGBM_BoosterResetParameter_R"
fun_name = "LGBM_BoosterResetParameter_R"
, ret = NULL
, private$handle
, params_str
Expand Down Expand Up @@ -227,7 +227,7 @@ Booster <- R6::R6Class(

# Reset training data on booster
lgb.call(
"LGBM_BoosterResetTrainingData_R"
fun_name = "LGBM_BoosterResetTrainingData_R"
, ret = NULL
, private$handle
, train_set$.__enclos_env__$private$get_handle()
Expand All @@ -245,7 +245,11 @@ Booster <- R6::R6Class(
stop("lgb.Booster.update: cannot update due to null objective function")
}
# Boost iteration from known objective
ret <- lgb.call("LGBM_BoosterUpdateOneIter_R", ret = NULL, private$handle)
ret <- lgb.call(
fun_name = "LGBM_BoosterUpdateOneIter_R"
, ret = NULL
, private$handle
)

} else {

Expand Down Expand Up @@ -292,7 +296,7 @@ Booster <- R6::R6Class(

# Return one iteration behind
lgb.call(
"LGBM_BoosterRollbackOneIter_R"
fun_name = "LGBM_BoosterRollbackOneIter_R"
, ret = NULL
, private$handle
)
Expand Down Expand Up @@ -438,7 +442,7 @@ Booster <- R6::R6Class(
, private$handle
, as.integer(num_iteration)
, as.integer(feature_importance_type)
, lgb.c_str(filename)
, lgb.c_str(x = filename)
)

return(invisible(self))
Expand Down Expand Up @@ -581,7 +585,7 @@ Booster <- R6::R6Class(

# Use buffer
private$predict_buffer[[data_name]] <- lgb.call(
"LGBM_BoosterGetPredict_R"
fun_name = "LGBM_BoosterGetPredict_R"
, ret = private$predict_buffer[[data_name]]
, private$handle
, as.integer(idx - 1L)
Expand Down Expand Up @@ -765,7 +769,7 @@ predict.lgb.Booster <- function(object,
reshape = FALSE,
...) {

if (!lgb.is.Booster(object)) {
if (!lgb.is.Booster(x = object)) {
stop("predict.lgb.Booster: object should be an ", sQuote("lgb.Booster"))
}

Expand Down Expand Up @@ -877,7 +881,7 @@ lgb.load <- function(filename = NULL, model_str = NULL) {
#' @export
lgb.save <- function(booster, filename, num_iteration = NULL) {

if (!lgb.is.Booster(booster)) {
if (!lgb.is.Booster(x = booster)) {
stop("lgb.save: booster should be an ", sQuote("lgb.Booster"))
}

Expand Down Expand Up @@ -926,7 +930,7 @@ lgb.save <- function(booster, filename, num_iteration = NULL) {
#' @export
lgb.dump <- function(booster, num_iteration = NULL) {

if (!lgb.is.Booster(booster)) {
if (!lgb.is.Booster(x = booster)) {
stop("lgb.save: booster should be an ", sQuote("lgb.Booster"))
}

Expand Down Expand Up @@ -981,7 +985,7 @@ lgb.dump <- function(booster, num_iteration = NULL) {
lgb.get.eval.result <- function(booster, data_name, eval_name, iters = NULL, is_err = FALSE) {

# Check if booster is booster
if (!lgb.is.Booster(booster)) {
if (!lgb.is.Booster(x = booster)) {
stop("lgb.get.eval.result: Can only use ", sQuote("lgb.Booster"), " to get eval result")
}

Expand Down
Loading