Unverified Commit 3fd48864 authored by Guangyu Zeng's avatar Guangyu Zeng Committed by GitHub
Browse files

[R-package] Add explicit return statement to R functions. (#3703)

* add explicit return statement to functions in callback.R

* add explicit return statement to functions in lgb.Booster.R

* add explicit return statement to functions in lgb.Dataset.R

* add explicit return statement to functions in lgb.Predictor.R

* add explicit return statement to functions in lgb.cv.R

* add explicit return statement to functions in lgb.interprete.R

* add explicit return statement to functions in lgb.plot.importance.R

* add explicit return statement to functions in saveRDS.lgb.Booster.R

* add explicit return statement to functions in utils.R

* add explicit return statement to functions in lgb.plot.interpretation.R

* add explicit return statement to functions in build_r.R

* fix typo

* return(self) -> return(invisible(self))

* fix some inconsistent indention

* fix test failure

* add another return() statement

* fix linting errors
parent 3fde0ce9
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
# [return] A named list, where each key is a parameter relevant to lgb.DataSet and each value is a character # [return] A named list, where each key is a parameter relevant to lgb.DataSet and each value is a character
# vector of corresponding aliases. # vector of corresponding aliases.
.DATASET_PARAMETERS <- function() { .DATASET_PARAMETERS <- function() {
return(list( return(
list(
"bin_construct_sample_cnt" = c( "bin_construct_sample_cnt" = c(
"bin_construct_sample_cnt" "bin_construct_sample_cnt"
, "subsample_for_bin" , "subsample_for_bin"
...@@ -74,7 +75,8 @@ ...@@ -74,7 +75,8 @@
, "weight" , "weight"
) )
, "zero_as_missing" = "zero_as_missing" , "zero_as_missing" = "zero_as_missing"
)) )
)
} }
# [description] List of respected parameter aliases. Wrapped in a function to take advantage of # [description] List of respected parameter aliases. Wrapped in a function to take advantage of
...@@ -115,10 +117,12 @@ ...@@ -115,10 +117,12 @@
# [returns] # [returns]
# A character vector # A character vector
.NO_METRIC_STRINGS <- function() { .NO_METRIC_STRINGS <- function() {
return(c( return(
c(
"na" "na"
, "None" , "None"
, "null" , "null"
, "custom" , "custom"
)) )
)
} }
...@@ -74,6 +74,8 @@ cb.reset.parameters <- function(new_params) { ...@@ -74,6 +74,8 @@ cb.reset.parameters <- function(new_params) {
} }
return(invisible(NULL))
} }
callback <- function(env) { callback <- function(env) {
...@@ -95,15 +97,17 @@ cb.reset.parameters <- function(new_params) { ...@@ -95,15 +97,17 @@ cb.reset.parameters <- function(new_params) {
}) })
if (!is.null(env$model)) { if (!is.null(env$model)) {
env$model$reset_parameter(params = pars) return(env$model$reset_parameter(params = pars))
} }
return(invisible(NULL))
} }
attr(callback, "call") <- match.call() attr(callback, "call") <- match.call()
attr(callback, "is_pre_iteration") <- TRUE attr(callback, "is_pre_iteration") <- TRUE
attr(callback, "name") <- "cb.reset.parameters" attr(callback, "name") <- "cb.reset.parameters"
callback return(callback)
} }
# Format the evaluation metric string # Format the evaluation metric string
...@@ -116,9 +120,9 @@ format.eval.string <- function(eval_res, eval_err = NULL) { ...@@ -116,9 +120,9 @@ format.eval.string <- function(eval_res, eval_err = NULL) {
# Check for empty evaluation error # Check for empty evaluation error
if (!is.null(eval_err)) { if (!is.null(eval_err)) {
sprintf("%s\'s %s:%g+%g", eval_res$data_name, eval_res$name, eval_res$value, eval_err) return(sprintf("%s\'s %s:%g+%g", eval_res$data_name, eval_res$name, eval_res$value, eval_err))
} else { } else {
sprintf("%s\'s %s:%g", eval_res$data_name, eval_res$name, eval_res$value) return(sprintf("%s\'s %s:%g", eval_res$data_name, eval_res$name, eval_res$value))
} }
} }
...@@ -150,7 +154,7 @@ merge.eval.string <- function(env) { ...@@ -150,7 +154,7 @@ merge.eval.string <- function(env) {
} }
paste0(msg, collapse = " ") return(paste0(msg, collapse = " "))
} }
...@@ -180,13 +184,15 @@ cb.print.evaluation <- function(period = 1L) { ...@@ -180,13 +184,15 @@ cb.print.evaluation <- function(period = 1L) {
} }
return(invisible(NULL))
} }
# Store attributes # Store attributes
attr(callback, "call") <- match.call() attr(callback, "call") <- match.call()
attr(callback, "name") <- "cb.print.evaluation" attr(callback, "name") <- "cb.print.evaluation"
callback return(callback)
} }
...@@ -253,13 +259,15 @@ cb.record.evaluation <- function() { ...@@ -253,13 +259,15 @@ cb.record.evaluation <- function() {
} }
return(invisible(NULL))
} }
# Store attributes # Store attributes
attr(callback, "call") <- match.call() attr(callback, "call") <- match.call()
attr(callback, "name") <- "cb.record.evaluation" attr(callback, "name") <- "cb.record.evaluation"
callback return(callback)
} }
...@@ -311,6 +319,8 @@ cb.early.stop <- function(stopping_rounds, first_metric_only = FALSE, verbose = ...@@ -311,6 +319,8 @@ cb.early.stop <- function(stopping_rounds, first_metric_only = FALSE, verbose =
} }
return(invisible(NULL))
} }
# Create callback # Create callback
...@@ -392,18 +402,21 @@ cb.early.stop <- function(stopping_rounds, first_metric_only = FALSE, verbose = ...@@ -392,18 +402,21 @@ cb.early.stop <- function(stopping_rounds, first_metric_only = FALSE, verbose =
env$met_early_stop <- TRUE env$met_early_stop <- TRUE
} }
} }
return(invisible(NULL))
} }
attr(callback, "call") <- match.call() attr(callback, "call") <- match.call()
attr(callback, "name") <- "cb.early.stop" attr(callback, "name") <- "cb.early.stop"
callback return(callback)
} }
# Extract callback names from the list of callbacks # Extract callback names from the list of callbacks
callback.names <- function(cb_list) { callback.names <- function(cb_list) {
unlist(lapply(cb_list, attr, "name")) return(unlist(lapply(cb_list, attr, "name")))
} }
add.cb <- function(cb_list, cb) { add.cb <- function(cb_list, cb) {
...@@ -426,13 +439,14 @@ add.cb <- function(cb_list, cb) { ...@@ -426,13 +439,14 @@ add.cb <- function(cb_list, cb) {
} }
# Return element # Return element
cb_list return(cb_list)
} }
categorize.callbacks <- function(cb_list) { categorize.callbacks <- function(cb_list) {
# Check for pre-iteration or post-iteration # Check for pre-iteration or post-iteration
return(
list( list(
pre_iter = Filter(function(x) { pre_iter = Filter(function(x) {
pre <- attr(x, "is_pre_iteration") pre <- attr(x, "is_pre_iteration")
...@@ -443,5 +457,6 @@ categorize.callbacks <- function(cb_list) { ...@@ -443,5 +457,6 @@ categorize.callbacks <- function(cb_list) {
is.null(pre) || !pre is.null(pre) || !pre
}, cb_list) }, cb_list)
) )
)
} }
...@@ -21,6 +21,8 @@ Booster <- R6::R6Class( ...@@ -21,6 +21,8 @@ Booster <- R6::R6Class(
} }
return(invisible(NULL))
}, },
# Initialize will create a starter booster # Initialize will create a starter booster
...@@ -137,6 +139,8 @@ Booster <- R6::R6Class( ...@@ -137,6 +139,8 @@ Booster <- R6::R6Class(
self$params <- params self$params <- params
return(invisible(NULL))
}, },
# Set training data name # Set training data name
...@@ -320,11 +324,13 @@ Booster <- R6::R6Class( ...@@ -320,11 +324,13 @@ Booster <- R6::R6Class(
current_iter = function() { current_iter = function() {
cur_iter <- 0L cur_iter <- 0L
return(
lgb.call( lgb.call(
fun_name = "LGBM_BoosterGetCurrentIteration_R" fun_name = "LGBM_BoosterGetCurrentIteration_R"
, ret = cur_iter , ret = cur_iter
, private$handle , private$handle
) )
)
}, },
...@@ -332,11 +338,13 @@ Booster <- R6::R6Class( ...@@ -332,11 +338,13 @@ Booster <- R6::R6Class(
upper_bound = function() { upper_bound = function() {
upper_bound <- 0.0 upper_bound <- 0.0
return(
lgb.call( lgb.call(
fun_name = "LGBM_BoosterGetUpperBoundValue_R" fun_name = "LGBM_BoosterGetUpperBoundValue_R"
, ret = upper_bound , ret = upper_bound
, private$handle , private$handle
) )
)
}, },
...@@ -344,11 +352,13 @@ Booster <- R6::R6Class( ...@@ -344,11 +352,13 @@ Booster <- R6::R6Class(
lower_bound = function() { lower_bound = function() {
lower_bound <- 0.0 lower_bound <- 0.0
return(
lgb.call( lgb.call(
fun_name = "LGBM_BoosterGetLowerBoundValue_R" fun_name = "LGBM_BoosterGetLowerBoundValue_R"
, ret = lower_bound , ret = lower_bound
, private$handle , private$handle
) )
)
}, },
...@@ -397,17 +407,19 @@ Booster <- R6::R6Class( ...@@ -397,17 +407,19 @@ Booster <- R6::R6Class(
} }
# Evaluate data # Evaluate data
return(
private$inner_eval( private$inner_eval(
data_name = name data_name = name
, data_idx = data_idx , data_idx = data_idx
, feval = feval , feval = feval
) )
)
}, },
# Evaluation training data # Evaluation training data
eval_train = function(feval = NULL) { eval_train = function(feval = NULL) {
private$inner_eval(private$name_train_set, 1L, feval) return(private$inner_eval(private$name_train_set, 1L, feval))
}, },
# Evaluation validation data # Evaluation validation data
...@@ -463,12 +475,14 @@ Booster <- R6::R6Class( ...@@ -463,12 +475,14 @@ Booster <- R6::R6Class(
} }
# Return model string # Return model string
return(lgb.call.return.str( return(
lgb.call.return.str(
fun_name = "LGBM_BoosterSaveModelToString_R" fun_name = "LGBM_BoosterSaveModelToString_R"
, private$handle , private$handle
, as.integer(num_iteration) , as.integer(num_iteration)
, as.integer(feature_importance_type) , as.integer(feature_importance_type)
)) )
)
}, },
...@@ -480,12 +494,14 @@ Booster <- R6::R6Class( ...@@ -480,12 +494,14 @@ Booster <- R6::R6Class(
num_iteration <- self$best_iter num_iteration <- self$best_iter
} }
return(
lgb.call.return.str( lgb.call.return.str(
fun_name = "LGBM_BoosterDumpModel_R" fun_name = "LGBM_BoosterDumpModel_R"
, private$handle , private$handle
, as.integer(num_iteration) , as.integer(num_iteration)
, as.integer(feature_importance_type) , as.integer(feature_importance_type)
) )
)
}, },
...@@ -510,6 +526,7 @@ Booster <- R6::R6Class( ...@@ -510,6 +526,7 @@ Booster <- R6::R6Class(
# Predict on new data # Predict on new data
predictor <- Predictor$new(private$handle, ...) predictor <- Predictor$new(private$handle, ...)
return(
predictor$predict( predictor$predict(
data = data data = data
, start_iteration = start_iteration , start_iteration = start_iteration
...@@ -520,12 +537,13 @@ Booster <- R6::R6Class( ...@@ -520,12 +537,13 @@ Booster <- R6::R6Class(
, header = header , header = header
, reshape = reshape , reshape = reshape
) )
)
}, },
# Transform into predictor # Transform into predictor
to_predictor = function() { to_predictor = function() {
Predictor$new(private$handle) return(Predictor$new(private$handle))
}, },
# Used for save # Used for save
...@@ -537,6 +555,8 @@ Booster <- R6::R6Class( ...@@ -537,6 +555,8 @@ Booster <- R6::R6Class(
# Overwrite model in object # Overwrite model in object
self$raw <- self$save_model_to_string(NULL) self$raw <- self$save_model_to_string(NULL)
return(invisible(NULL))
} }
), ),
...@@ -780,6 +800,7 @@ predict.lgb.Booster <- function(object, ...@@ -780,6 +800,7 @@ predict.lgb.Booster <- function(object,
} }
# Return booster predictions # Return booster predictions
return(
object$predict( object$predict(
data = data data = data
, start_iteration = start_iteration , start_iteration = start_iteration
...@@ -791,6 +812,7 @@ predict.lgb.Booster <- function(object, ...@@ -791,6 +812,7 @@ predict.lgb.Booster <- function(object,
, reshape = reshape , reshape = reshape
, ... , ...
) )
)
} }
#' @name lgb.load #' @name lgb.load
...@@ -896,10 +918,12 @@ lgb.save <- function(booster, filename, num_iteration = NULL) { ...@@ -896,10 +918,12 @@ lgb.save <- function(booster, filename, num_iteration = NULL) {
} }
# Store booster # Store booster
return(
invisible(booster$save_model( invisible(booster$save_model(
filename = filename filename = filename
, num_iteration = num_iteration , num_iteration = num_iteration
)) ))
)
} }
...@@ -941,7 +965,7 @@ lgb.dump <- function(booster, num_iteration = NULL) { ...@@ -941,7 +965,7 @@ lgb.dump <- function(booster, num_iteration = NULL) {
} }
# Return booster at requested iteration # Return booster at requested iteration
booster$dump_model(num_iteration = num_iteration) return(booster$dump_model(num_iteration = num_iteration))
} }
...@@ -1045,5 +1069,5 @@ lgb.get.eval.result <- function(booster, data_name, eval_name, iters = NULL, is_ ...@@ -1045,5 +1069,5 @@ lgb.get.eval.result <- function(booster, data_name, eval_name, iters = NULL, is_
iters <- iters - delta iters <- iters - delta
# Return requested result # Return requested result
as.numeric(result[iters]) return(as.numeric(result[iters]))
} }
...@@ -18,6 +18,8 @@ Dataset <- R6::R6Class( ...@@ -18,6 +18,8 @@ Dataset <- R6::R6Class(
} }
return(invisible(NULL))
}, },
# Initialize will create a starter dataset # Initialize will create a starter dataset
...@@ -85,6 +87,8 @@ Dataset <- R6::R6Class( ...@@ -85,6 +87,8 @@ Dataset <- R6::R6Class(
private$info <- info private$info <- info
private$version <- 0L private$version <- 0L
return(invisible(NULL))
}, },
create_valid = function(data, create_valid = function(data,
...@@ -325,6 +329,7 @@ Dataset <- R6::R6Class( ...@@ -325,6 +329,7 @@ Dataset <- R6::R6Class(
num_col <- 0L num_col <- 0L
# Get numeric data and numeric features # Get numeric data and numeric features
return(
c( c(
lgb.call( lgb.call(
fun_name = "LGBM_DatasetGetNumData_R" fun_name = "LGBM_DatasetGetNumData_R"
...@@ -337,12 +342,13 @@ Dataset <- R6::R6Class( ...@@ -337,12 +342,13 @@ Dataset <- R6::R6Class(
, private$handle , private$handle
) )
) )
)
} else if (is.matrix(private$raw_data) || methods::is(private$raw_data, "dgCMatrix")) { } else if (is.matrix(private$raw_data) || methods::is(private$raw_data, "dgCMatrix")) {
# Check if dgCMatrix (sparse matrix column compressed) # Check if dgCMatrix (sparse matrix column compressed)
# NOTE: requires Matrix package # NOTE: requires Matrix package
dim(private$raw_data) return(dim(private$raw_data))
} else { } else {
...@@ -368,12 +374,12 @@ Dataset <- R6::R6Class( ...@@ -368,12 +374,12 @@ Dataset <- R6::R6Class(
, private$handle , private$handle
) )
private$colnames <- as.character(base::strsplit(cnames, "\t")[[1L]]) private$colnames <- as.character(base::strsplit(cnames, "\t")[[1L]])
private$colnames return(private$colnames)
} else if (is.matrix(private$raw_data) || methods::is(private$raw_data, "dgCMatrix")) { } else if (is.matrix(private$raw_data) || methods::is(private$raw_data, "dgCMatrix")) {
# Check if dgCMatrix (sparse matrix column compressed) # Check if dgCMatrix (sparse matrix column compressed)
colnames(private$raw_data) return(colnames(private$raw_data))
} else { } else {
...@@ -470,7 +476,7 @@ Dataset <- R6::R6Class( ...@@ -470,7 +476,7 @@ Dataset <- R6::R6Class(
} }
} }
private$info[[name]] return(private$info[[name]])
}, },
...@@ -522,6 +528,7 @@ Dataset <- R6::R6Class( ...@@ -522,6 +528,7 @@ Dataset <- R6::R6Class(
slice = function(idxset, ...) { slice = function(idxset, ...) {
# Perform slicing # Perform slicing
return(
Dataset$new( Dataset$new(
data = NULL data = NULL
, params = private$params , params = private$params
...@@ -534,6 +541,7 @@ Dataset <- R6::R6Class( ...@@ -534,6 +541,7 @@ Dataset <- R6::R6Class(
, info = NULL , info = NULL
, ... , ...
) )
)
}, },
...@@ -679,7 +687,7 @@ Dataset <- R6::R6Class( ...@@ -679,7 +687,7 @@ Dataset <- R6::R6Class(
if (lgb.is.null.handle(x = private$handle)) { if (lgb.is.null.handle(x = private$handle)) {
self$construct() self$construct()
} }
private$handle return(private$handle)
}, },
...@@ -753,6 +761,7 @@ lgb.Dataset <- function(data, ...@@ -753,6 +761,7 @@ lgb.Dataset <- function(data,
...) { ...) {
# Create new dataset # Create new dataset
return(
invisible(Dataset$new( invisible(Dataset$new(
data = data data = data
, params = params , params = params
...@@ -765,6 +774,7 @@ lgb.Dataset <- function(data, ...@@ -765,6 +774,7 @@ lgb.Dataset <- function(data,
, info = info , info = info
, ... , ...
)) ))
)
} }
...@@ -796,7 +806,7 @@ lgb.Dataset.create.valid <- function(dataset, data, info = list(), ...) { ...@@ -796,7 +806,7 @@ lgb.Dataset.create.valid <- function(dataset, data, info = list(), ...) {
} }
# Create validation dataset # Create validation dataset
invisible(dataset$create_valid(data = data, info = info, ...)) return(invisible(dataset$create_valid(data = data, info = info, ...)))
} }
...@@ -822,7 +832,7 @@ lgb.Dataset.construct <- function(dataset) { ...@@ -822,7 +832,7 @@ lgb.Dataset.construct <- function(dataset) {
} }
# Construct the dataset # Construct the dataset
invisible(dataset$construct()) return(invisible(dataset$construct()))
} }
...@@ -856,7 +866,7 @@ dim.lgb.Dataset <- function(x, ...) { ...@@ -856,7 +866,7 @@ dim.lgb.Dataset <- function(x, ...) {
stop("dim.lgb.Dataset: input data should be an lgb.Dataset object") stop("dim.lgb.Dataset: input data should be an lgb.Dataset object")
} }
x$dim() return(x$dim())
} }
...@@ -893,7 +903,7 @@ dimnames.lgb.Dataset <- function(x) { ...@@ -893,7 +903,7 @@ dimnames.lgb.Dataset <- function(x) {
} }
# Return dimension names # Return dimension names
list(NULL, x$get_colnames()) return(list(NULL, x$get_colnames()))
} }
...@@ -932,7 +942,7 @@ dimnames.lgb.Dataset <- function(x) { ...@@ -932,7 +942,7 @@ dimnames.lgb.Dataset <- function(x) {
# Set column names properly, and return # Set column names properly, and return
x$set_colnames(colnames = value[[2L]]) x$set_colnames(colnames = value[[2L]])
x return(x)
} }
...@@ -970,7 +980,7 @@ slice.lgb.Dataset <- function(dataset, idxset, ...) { ...@@ -970,7 +980,7 @@ slice.lgb.Dataset <- function(dataset, idxset, ...) {
} }
# Return sliced set # Return sliced set
invisible(dataset$slice(idxset = idxset, ...)) return(invisible(dataset$slice(idxset = idxset, ...)))
} }
...@@ -1020,7 +1030,7 @@ getinfo.lgb.Dataset <- function(dataset, name, ...) { ...@@ -1020,7 +1030,7 @@ getinfo.lgb.Dataset <- function(dataset, name, ...) {
stop("getinfo.lgb.Dataset: input dataset should be an lgb.Dataset object") stop("getinfo.lgb.Dataset: input dataset should be an lgb.Dataset object")
} }
dataset$getinfo(name = name) return(dataset$getinfo(name = name))
} }
...@@ -1074,7 +1084,7 @@ setinfo.lgb.Dataset <- function(dataset, name, info, ...) { ...@@ -1074,7 +1084,7 @@ setinfo.lgb.Dataset <- function(dataset, name, info, ...) {
} }
# Set information # Set information
invisible(dataset$setinfo(name = name, info = info)) return(invisible(dataset$setinfo(name = name, info = info)))
} }
#' @name lgb.Dataset.set.categorical #' @name lgb.Dataset.set.categorical
...@@ -1106,7 +1116,7 @@ lgb.Dataset.set.categorical <- function(dataset, categorical_feature) { ...@@ -1106,7 +1116,7 @@ lgb.Dataset.set.categorical <- function(dataset, categorical_feature) {
} }
# Set categoricals # Set categoricals
invisible(dataset$set_categorical_feature(categorical_feature = categorical_feature)) return(invisible(dataset$set_categorical_feature(categorical_feature = categorical_feature)))
} }
...@@ -1138,7 +1148,7 @@ lgb.Dataset.set.reference <- function(dataset, reference) { ...@@ -1138,7 +1148,7 @@ lgb.Dataset.set.reference <- function(dataset, reference) {
} }
# Set reference # Set reference
invisible(dataset$set_reference(reference = reference)) return(invisible(dataset$set_reference(reference = reference)))
} }
#' @name lgb.Dataset.save #' @name lgb.Dataset.save
...@@ -1171,5 +1181,5 @@ lgb.Dataset.save <- function(dataset, fname) { ...@@ -1171,5 +1181,5 @@ lgb.Dataset.save <- function(dataset, fname) {
} }
# Store binary # Store binary
invisible(dataset$save_binary(fname = fname)) return(invisible(dataset$save_binary(fname = fname)))
} }
...@@ -23,6 +23,8 @@ Predictor <- R6::R6Class( ...@@ -23,6 +23,8 @@ Predictor <- R6::R6Class(
} }
return(invisible(NULL))
}, },
# Initialize will create a starter model # Initialize will create a starter model
...@@ -59,17 +61,21 @@ Predictor <- R6::R6Class( ...@@ -59,17 +61,21 @@ Predictor <- R6::R6Class(
class(handle) <- "lgb.Booster.handle" class(handle) <- "lgb.Booster.handle"
private$handle <- handle private$handle <- handle
return(invisible(NULL))
}, },
# Get current iteration # Get current iteration
current_iter = function() { current_iter = function() {
cur_iter <- 0L cur_iter <- 0L
return(
lgb.call( lgb.call(
fun_name = "LGBM_BoosterGetCurrentIteration_R" fun_name = "LGBM_BoosterGetCurrentIteration_R"
, ret = cur_iter , ret = cur_iter
, private$handle , private$handle
) )
)
}, },
......
...@@ -9,10 +9,11 @@ CVBooster <- R6::R6Class( ...@@ -9,10 +9,11 @@ CVBooster <- R6::R6Class(
boosters = list(), boosters = list(),
initialize = function(x) { initialize = function(x) {
self$boosters <- x self$boosters <- x
return(invisible(NULL))
}, },
reset_parameter = function(new_params) { reset_parameter = function(new_params) {
for (x in boosters) { x$reset_parameter(new_params) } for (x in boosters) { x$reset_parameter(new_params) }
self return(invisible(self))
} }
) )
) )
...@@ -563,7 +564,7 @@ lgb.stratified.folds <- function(y, k = 10L) { ...@@ -563,7 +564,7 @@ lgb.stratified.folds <- function(y, k = 10L) {
out <- split(seq(along = y), foldVector) out <- split(seq(along = y), foldVector)
names(out) <- NULL names(out) <- NULL
out return(out)
} }
lgb.merge.cv.result <- function(msg, showsd = TRUE) { lgb.merge.cv.result <- function(msg, showsd = TRUE) {
...@@ -615,9 +616,11 @@ lgb.merge.cv.result <- function(msg, showsd = TRUE) { ...@@ -615,9 +616,11 @@ lgb.merge.cv.result <- function(msg, showsd = TRUE) {
} }
# Return errors # Return errors
return(
list( list(
eval_list = ret_eval eval_list = ret_eval
, eval_err_list = ret_eval_err , eval_err_list = ret_eval_err
) )
)
} }
...@@ -137,10 +137,12 @@ single.tree.interprete <- function(tree_dt, ...@@ -137,10 +137,12 @@ single.tree.interprete <- function(tree_dt,
, current_value = leaf_dt[["leaf_value"]] , current_value = leaf_dt[["leaf_value"]]
) )
return(
data.table::data.table( data.table::data.table(
Feature = feature_seq Feature = feature_seq
, Contribution = diff.default(value_seq) , Contribution = diff.default(value_seq)
) )
)
} }
......
...@@ -91,6 +91,6 @@ lgb.plot.importance <- function(tree_imp, ...@@ -91,6 +91,6 @@ lgb.plot.importance <- function(tree_imp,
, las = 1L , las = 1L
)] )]
invisible(tree_imp) return(invisible(tree_imp))
} }
...@@ -124,6 +124,7 @@ lgb.plot.interpretation <- function(tree_interpretation_dt, ...@@ -124,6 +124,7 @@ lgb.plot.interpretation <- function(tree_interpretation_dt,
} }
} }
return(invisible(NULL))
} }
#' @importFrom graphics barplot #' @importFrom graphics barplot
......
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
# are returned from the C++ side. For example, if you use `metric = "mse"` in your code, # are returned from the C++ side. For example, if you use `metric = "mse"` in your code,
# the metric name `"l2"` will be returned. # the metric name `"l2"` will be returned.
.METRICS_HIGHER_BETTER <- function() { .METRICS_HIGHER_BETTER <- function() {
return(c( return(
c(
"l1" = FALSE "l1" = FALSE
, "l2" = FALSE , "l2" = FALSE
, "mape" = FALSE , "mape" = FALSE
...@@ -31,5 +32,6 @@ ...@@ -31,5 +32,6 @@
, "cross_entropy" = FALSE , "cross_entropy" = FALSE
, "cross_entropy_lambda" = FALSE , "cross_entropy_lambda" = FALSE
, "kullback_leibler" = FALSE , "kullback_leibler" = FALSE
)) )
)
} }
...@@ -66,6 +66,8 @@ saveRDS.lgb.Booster <- function(object, ...@@ -66,6 +66,8 @@ saveRDS.lgb.Booster <- function(object,
# Free model from memory # Free model from memory
object$raw <- NA object$raw <- NA
return(invisible(NULL))
} else { } else {
saveRDS( saveRDS(
...@@ -77,6 +79,8 @@ saveRDS.lgb.Booster <- function(object, ...@@ -77,6 +79,8 @@ saveRDS.lgb.Booster <- function(object,
, refhook = refhook , refhook = refhook
) )
return(invisible(NULL))
} }
} }
lgb.is.Booster <- function(x) { lgb.is.Booster <- function(x) {
lgb.check.r6.class(object = x, name = "lgb.Booster") return(lgb.check.r6.class(object = x, name = "lgb.Booster"))
} }
lgb.is.Dataset <- function(x) { lgb.is.Dataset <- function(x) {
lgb.check.r6.class(object = x, name = "lgb.Dataset") return(lgb.check.r6.class(object = x, name = "lgb.Dataset"))
} }
lgb.null.handle <- function() { lgb.null.handle <- function() {
...@@ -15,7 +15,7 @@ lgb.null.handle <- function() { ...@@ -15,7 +15,7 @@ lgb.null.handle <- function() {
} }
lgb.is.null.handle <- function(x) { lgb.is.null.handle <- function(x) {
is.null(x) || is.na(x) return(is.null(x) || is.na(x))
} }
lgb.encode.char <- function(arr, len) { lgb.encode.char <- function(arr, len) {
...@@ -54,6 +54,9 @@ lgb.last_error <- function() { ...@@ -54,6 +54,9 @@ lgb.last_error <- function() {
} }
stop("api error: ", lgb.encode.char(arr = err_msg, len = act_len)) stop("api error: ", lgb.encode.char(arr = err_msg, len = act_len))
return(invisible(NULL))
} }
lgb.call <- function(fun_name, ret, ...) { lgb.call <- function(fun_name, ret, ...) {
...@@ -232,14 +235,14 @@ lgb.c_str <- function(x) { ...@@ -232,14 +235,14 @@ lgb.c_str <- function(x) {
ret <- charToRaw(as.character(x)) ret <- charToRaw(as.character(x))
ret <- c(ret, as.raw(0L)) ret <- c(ret, as.raw(0L))
ret return(ret)
} }
lgb.check.r6.class <- function(object, name) { lgb.check.r6.class <- function(object, name) {
# Check for non-existence of R6 class or named class # Check for non-existence of R6 class or named class
all(c("R6", name) %in% class(object)) return(all(c("R6", name) %in% class(object)))
} }
......
...@@ -53,6 +53,7 @@ install_libs_content <- .replace_flag("use_msys2", USING_MSYS2, install_libs_con ...@@ -53,6 +53,7 @@ install_libs_content <- .replace_flag("use_msys2", USING_MSYS2, install_libs_con
if (!all(res)) { if (!all(res)) {
stop("Copying files failed!") stop("Copying files failed!")
} }
return(invisible(NULL))
} }
# system() will not raise an R exception if the process called # system() will not raise an R exception if the process called
......
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