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] standardize naming of internal functions #6179

Merged
merged 4 commits into from
Nov 13, 2023
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
8 changes: 4 additions & 4 deletions R-package/R/callback.R
Original file line number Diff line number Diff line change
Expand Up @@ -323,17 +323,17 @@ cb_early_stop <- function(stopping_rounds, first_metric_only, verbose) {
}

# Extract callback names from the list of callbacks
callback.names <- function(cb_list) {
.callback_names <- function(cb_list) {
return(unlist(lapply(cb_list, attr, "name")))
}

add.cb <- function(cb_list, cb) {
.add_cb <- function(cb_list, cb) {

# Combine two elements
cb_list <- c(cb_list, cb)

# Set names of elements
names(cb_list) <- callback.names(cb_list = cb_list)
names(cb_list) <- .callback_names(cb_list = cb_list)

if ("cb_early_stop" %in% names(cb_list)) {

Expand All @@ -349,7 +349,7 @@ add.cb <- function(cb_list, cb) {

}

categorize.callbacks <- function(cb_list) {
.categorize_callbacks <- function(cb_list) {

# Check for pre-iteration or post-iteration
return(
Expand Down
34 changes: 17 additions & 17 deletions R-package/R/lgb.Booster.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ Booster <- R6::R6Class(

if (!is.null(train_set)) {

if (!lgb.is.Dataset(train_set)) {
if (!.is_Dataset(train_set)) {
stop("lgb.Booster: Can only use lgb.Dataset as training data")
}
train_set_handle <- train_set$.__enclos_env__$private$get_handle()
params <- utils::modifyList(params, train_set$get_params())
params_str <- lgb.params2str(params = params)
params_str <- .params2str(params = params)
# Store booster handle
handle <- .Call(
LGBM_BoosterCreate_R
Expand Down Expand Up @@ -130,7 +130,7 @@ Booster <- R6::R6Class(
# Add validation data
add_valid = function(data, name) {

if (!lgb.is.Dataset(data)) {
if (!.is_Dataset(data)) {
stop("lgb.Booster.add_valid: Can only use lgb.Dataset as validation data")
}

Expand Down Expand Up @@ -167,7 +167,7 @@ Booster <- R6::R6Class(
params <- utils::modifyList(self$params, params)
}

params_str <- lgb.params2str(params = params)
params_str <- .params2str(params = params)

self$restore_handle()

Expand All @@ -193,7 +193,7 @@ Booster <- R6::R6Class(

if (!is.null(train_set)) {

if (!lgb.is.Dataset(train_set)) {
if (!.is_Dataset(train_set)) {
stop("lgb.Booster.update: Only can use lgb.Dataset as training data")
}

Expand Down Expand Up @@ -340,7 +340,7 @@ Booster <- R6::R6Class(
# Evaluate data on metrics
eval = function(data, name, feval = NULL) {

if (!lgb.is.Dataset(data)) {
if (!.is_Dataset(data)) {
stop("lgb.Booster.eval: Can only use lgb.Dataset to eval")
}

Expand Down Expand Up @@ -508,17 +508,17 @@ Booster <- R6::R6Class(
# NOTE: doing this here instead of in Predictor$predict() to keep
# Predictor$predict() as fast as possible
if (length(params) > 0L) {
params <- lgb.check.wrapper_param(
params <- .check_wrapper_param(
main_param_name = "predict_raw_score"
, params = params
, alternative_kwarg_value = rawscore
)
params <- lgb.check.wrapper_param(
params <- .check_wrapper_param(
main_param_name = "predict_leaf_index"
, params = params
, alternative_kwarg_value = predleaf
)
params <- lgb.check.wrapper_param(
params <- .check_wrapper_param(
main_param_name = "predict_contrib"
, params = params
, alternative_kwarg_value = predcontrib
Expand Down Expand Up @@ -586,7 +586,7 @@ Booster <- R6::R6Class(
, predcontrib
, start_iteration
, num_iteration
, lgb.params2str(params = params)
, .params2str(params = params)
)

private$fast_predict_config <- list(
Expand Down Expand Up @@ -622,7 +622,7 @@ Booster <- R6::R6Class(
},

check_null_handle = function() {
return(lgb.is.null.handle(private$handle))
return(.is_null_handle(private$handle))
},

restore_handle = function() {
Expand Down Expand Up @@ -959,7 +959,7 @@ predict.lgb.Booster <- function(object,
params = list(),
...) {

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

Expand Down Expand Up @@ -1114,7 +1114,7 @@ lgb.configure_fast_predict <- function(model,
num_iteration = NULL,
type = "response",
params = list()) {
if (!lgb.is.Booster(x = model)) {
if (!.is_Booster(x = model)) {
stop("lgb.configure_fast_predict: model should be an ", sQuote("lgb.Booster"))
}
if (type == "class") {
Expand Down Expand Up @@ -1160,7 +1160,7 @@ lgb.configure_fast_predict <- function(model,
print.lgb.Booster <- function(x, ...) {
# nolint start
handle <- x$.__enclos_env__$private$handle
handle_is_null <- lgb.is.null.handle(handle)
handle_is_null <- .is_null_handle(handle)

if (!handle_is_null) {
ntrees <- x$current_iter()
Expand Down Expand Up @@ -1316,7 +1316,7 @@ lgb.load <- function(filename = NULL, model_str = NULL) {
#' @export
lgb.save <- function(booster, filename, num_iteration = NULL) {

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

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

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion R-package/R/lgb.DataProcessor.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ DataProcessor <- R6::R6Class(
)
}
data_num_class <- length(self$factor_levels)
params <- lgb.check.wrapper_param(
params <- .check_wrapper_param(
main_param_name = "num_class"
, params = params
, alternative_kwarg_value = data_num_class
Expand Down
Loading