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] remove unnecessary comments #3356

Merged
merged 6 commits into from
Sep 11, 2020
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: 0 additions & 8 deletions R-package/R/callback.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ CB_ENV <- R6::R6Class(

cb.reset.parameters <- function(new_params) {

# Check for parameter list
if (!identical(class(new_params), "list")) {
stop(sQuote("new_params"), " must be a list")
}
Expand Down Expand Up @@ -151,7 +150,6 @@ merge.eval.string <- function(env) {

}

# Return tabulated separated message
paste0(msg, collapse = "\t")

}
Expand Down Expand Up @@ -188,7 +186,6 @@ cb.print.evaluation <- function(period = 1L) {
attr(callback, "call") <- match.call()
attr(callback, "name") <- "cb.print.evaluation"

# Return callback
callback

}
Expand All @@ -198,7 +195,6 @@ cb.record.evaluation <- function() {
# Create callback
callback <- function(env) {

# Return empty if empty evaluation list
if (length(env$eval_list) <= 0L) {
return()
}
Expand Down Expand Up @@ -263,14 +259,12 @@ cb.record.evaluation <- function() {
attr(callback, "call") <- match.call()
attr(callback, "name") <- "cb.record.evaluation"

# Return callback
callback

}

cb.early.stop <- function(stopping_rounds, first_metric_only = FALSE, verbose = TRUE) {

# Initialize variables
factor_to_bigger_better <- NULL
best_iter <- NULL
best_score <- NULL
Expand Down Expand Up @@ -397,11 +391,9 @@ cb.early.stop <- function(stopping_rounds, first_metric_only = FALSE, verbose =
}
}

# Set attributes
attr(callback, "call") <- match.call()
attr(callback, "name") <- "cb.early.stop"

# Return callback
callback

}
Expand Down
14 changes: 0 additions & 14 deletions R-package/R/lgb.Booster.R
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ Booster <- R6::R6Class(
private$num_dataset <- private$num_dataset + 1L
private$is_predicted_cur_iter <- c(private$is_predicted_cur_iter, FALSE)

# Return self
return(invisible(self))

},
Expand All @@ -200,7 +199,6 @@ Booster <- R6::R6Class(
, params_str
)

# Return self
return(invisible(self))

},
Expand Down Expand Up @@ -304,7 +302,6 @@ Booster <- R6::R6Class(
private$is_predicted_cur_iter[[i]] <- FALSE
}

# Return self
return(invisible(self))

},
Expand Down Expand Up @@ -418,7 +415,6 @@ Booster <- R6::R6Class(
)
}

# Return ret
return(ret)

},
Expand All @@ -441,7 +437,6 @@ Booster <- R6::R6Class(
, lgb.c_str(filename)
)

# Return self
return(invisible(self))
},

Expand Down Expand Up @@ -471,7 +466,6 @@ Booster <- R6::R6Class(
num_iteration <- self$best_iter
}

# Return dumped model
lgb.call.return.str(
"LGBM_BoosterDumpModel_R"
, private$handle
Expand Down Expand Up @@ -582,7 +576,6 @@ Booster <- R6::R6Class(
private$is_predicted_cur_iter[[idx]] <- TRUE
}

# Return prediction buffer
return(private$predict_buffer[[data_name]])
},

Expand Down Expand Up @@ -614,7 +607,6 @@ Booster <- R6::R6Class(

}

# Return evaluation names
return(private$eval_names)

},
Expand Down Expand Up @@ -690,7 +682,6 @@ Booster <- R6::R6Class(
ret <- append(ret, list(res))
}

# Return ret
return(ret)

}
Expand Down Expand Up @@ -761,7 +752,6 @@ predict.lgb.Booster <- function(object,
reshape = FALSE,
...) {

# Check booster existence
if (!lgb.is.Booster(object)) {
stop("predict.lgb.Booster: object should be an ", sQuote("lgb.Booster"))
}
Expand Down Expand Up @@ -874,12 +864,10 @@ lgb.load <- function(filename = NULL, model_str = NULL) {
#' @export
lgb.save <- function(booster, filename, num_iteration = NULL) {

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

# Check if file name is character
if (!(is.character(filename) && length(filename) == 1L)) {
stop("lgb.save: filename should be a string")
}
Expand Down Expand Up @@ -922,7 +910,6 @@ lgb.save <- function(booster, filename, num_iteration = NULL) {
#' @export
lgb.dump <- function(booster, num_iteration = NULL) {

# Check if booster is booster
if (!lgb.is.Booster(booster)) {
stop("lgb.save: booster should be an ", sQuote("lgb.Booster"))
}
Expand Down Expand Up @@ -1014,7 +1001,6 @@ lgb.get.eval.result <- function(booster, data_name, eval_name, iters = NULL, is_
stop("lgb.get.eval.result: wrong eval name")
}

# Create result
result <- booster$record_evals[[data_name]][[eval_name]][[.EVAL_KEY()]]

# Check if error is requested
Expand Down
11 changes: 0 additions & 11 deletions R-package/R/lgb.Dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ Dataset <- R6::R6Class(
, ...
)

# Return ret
return(invisible(ret))

},
Expand Down Expand Up @@ -312,7 +311,6 @@ Dataset <- R6::R6Class(
stop("lgb.Dataset.construct: label should be set")
}

# Return self
return(invisible(self))

},
Expand Down Expand Up @@ -405,7 +403,6 @@ Dataset <- R6::R6Class(

}

# Return self
return(invisible(self))

},
Expand Down Expand Up @@ -504,7 +501,6 @@ Dataset <- R6::R6Class(

}

# Return self
return(invisible(self))

},
Expand Down Expand Up @@ -677,7 +673,6 @@ Dataset <- R6::R6Class(
# Set predictor
set_predictor = function(predictor) {

# Return self is identical predictor
if (identical(private$predictor, predictor)) {
return(invisible(self))
}
Expand Down Expand Up @@ -847,7 +842,6 @@ dim.lgb.Dataset <- function(x, ...) {
stop("dim.lgb.Dataset: input data should be an lgb.Dataset object")
}

# Return dimensions
x$dim()

}
Expand Down Expand Up @@ -902,10 +896,8 @@ dimnames.lgb.Dataset <- function(x) {
stop("lgb.Dataset does not have rownames")
}

# Check for second value missing
if (is.null(value[[2L]])) {

# No column names
x$set_colnames(NULL)
return(x)

Expand Down Expand Up @@ -1010,7 +1002,6 @@ getinfo.lgb.Dataset <- function(dataset, name, ...) {
stop("getinfo.lgb.Dataset: input dataset should be an lgb.Dataset object")
}

# Return information
dataset$getinfo(name)

}
Expand Down Expand Up @@ -1059,7 +1050,6 @@ setinfo <- function(dataset, ...) {
#' @export
setinfo.lgb.Dataset <- function(dataset, name, info, ...) {

# Check if dataset is not a dataset
if (!lgb.is.Dataset(dataset)) {
stop("setinfo.lgb.Dataset: input dataset should be an lgb.Dataset object")
}
Expand Down Expand Up @@ -1092,7 +1082,6 @@ setinfo.lgb.Dataset <- function(dataset, name, info, ...) {
#' @export
lgb.Dataset.set.categorical <- function(dataset, categorical_feature) {

# Check if dataset is not a dataset
if (!lgb.is.Dataset(dataset)) {
stop("lgb.Dataset.set.categorical: input dataset should be an lgb.Dataset object")
}
Expand Down
7 changes: 2 additions & 5 deletions R-package/R/lgb.Predictor.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ Predictor <- R6::R6Class(

} else {

# Model file is unknown
stop("lgb.Predictor: modelfile must be either a character filename or an lgb.Booster.handle")

}
Expand Down Expand Up @@ -93,7 +92,6 @@ Predictor <- R6::R6Class(
start_iteration <- 0L
}

# Set temporary variable
num_row <- 0L

# Check if data is a file name and not a matrix
Expand Down Expand Up @@ -149,7 +147,8 @@ Predictor <- R6::R6Class(

# Check if data is a matrix
if (is.matrix(data)) {
# Check whether matrix is the correct type first ("double")
# this if() prevents the memory and computational costs
# of converting something that is already "double" to "double"
if (storage.mode(data) != "double") {
storage.mode(data) <- "double"
}
Expand Down Expand Up @@ -193,7 +192,6 @@ Predictor <- R6::R6Class(

} else {

# Cannot predict on unknown class
stop("predict: cannot predict on data of class ", sQuote(class(data)))

}
Expand Down Expand Up @@ -227,7 +225,6 @@ Predictor <- R6::R6Class(

}

# Return predictions
return(preds)

}
Expand Down
14 changes: 4 additions & 10 deletions R-package/R/lgb.cv.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ lgb.cv <- function(params = list()
, ...
) {

# validate parameters
if (nrounds <= 0L) {
stop("nrounds should be greater than zero")
}
Expand All @@ -118,9 +117,10 @@ lgb.cv <- function(params = list()
params$objective <- "NONE"
}

# If loss is a single function, store it as a 1-element list
# If eval is a single function, store it as a 1-element list
# (for backwards compatibility). If it is a list of functions, store
# all of them
# all of them. This makes it possible to pass any mix of strings like "auc"
# and custom functions to eval
if (is.function(eval)) {
eval_functions <- list(eval)
}
Expand Down Expand Up @@ -276,7 +276,6 @@ lgb.cv <- function(params = list()
)
}

# Categorize callbacks
cb <- categorize.callbacks(callbacks)

# Construct booster for each fold. The data.table() code below is used to
Expand Down Expand Up @@ -354,7 +353,6 @@ lgb.cv <- function(params = list()
env$iteration <- i
env$eval_list <- list()

# Loop through "pre_iter" element
for (f in cb$pre_iter) {
f(env)
}
Expand Down Expand Up @@ -430,7 +428,6 @@ lgb.cv <- function(params = list()
})
}

# Return booster
return(cv_booster)

}
Expand Down Expand Up @@ -493,7 +490,6 @@ generate.cv.folds <- function(nfold, nrows, stratified, label, group, params) {

}

# Return folds
return(folds)

}
Expand Down Expand Up @@ -564,7 +560,6 @@ lgb.stratified.folds <- function(y, k = 10L) {

}

# Return data
out <- split(seq(along = y), foldVector)
names(out) <- NULL
out
Expand Down Expand Up @@ -592,15 +587,14 @@ lgb.merge.cv.result <- function(msg, showsd = TRUE) {
})

# Get evaluation. Just taking the first element here to
# get structture (name, higher_bettter, data_name)
# get structure (name, higher_better, data_name)
ret_eval <- msg[[1L]]

# Go through evaluation length items
for (j in seq_len(eval_len)) {
ret_eval[[j]]$value <- mean(eval_result[[j]])
}

# Preinit evaluation error
ret_eval_err <- NULL

# Check for standard deviation
Expand Down
1 change: 0 additions & 1 deletion R-package/R/lgb.importance.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ lgb.importance <- function(model, percentage = TRUE) {
)]
}

# Return importance table
return(tree_imp_dt)

}
Loading