Commit 6e07a8d5 authored by Guolin Ke's avatar Guolin Ke
Browse files

[R] Delay the problem of slowdown when returning R6 object.

parent 97ca38d1
...@@ -108,7 +108,7 @@ Booster <- R6Class( ...@@ -108,7 +108,7 @@ Booster <- R6Class(
# Set name # Set name
private$name_train_set <- name private$name_train_set <- name
self return(invisible(self))
}, },
...@@ -143,7 +143,7 @@ Booster <- R6Class( ...@@ -143,7 +143,7 @@ Booster <- R6Class(
private$is_predicted_cur_iter <- c(private$is_predicted_cur_iter, FALSE) private$is_predicted_cur_iter <- c(private$is_predicted_cur_iter, FALSE)
# Return self # Return self
return(self) return(invisible(self))
}, },
...@@ -161,7 +161,7 @@ Booster <- R6Class( ...@@ -161,7 +161,7 @@ Booster <- R6Class(
params_str) params_str)
# Return self # Return self
return(self) return(invisible(self))
}, },
...@@ -229,7 +229,6 @@ Booster <- R6Class( ...@@ -229,7 +229,6 @@ Booster <- R6Class(
private$is_predicted_cur_iter[[i]] <- FALSE private$is_predicted_cur_iter[[i]] <- FALSE
} }
# Return self
return(ret) return(ret)
}, },
...@@ -248,7 +247,7 @@ Booster <- R6Class( ...@@ -248,7 +247,7 @@ Booster <- R6Class(
} }
# Return self # Return self
return(self) return(invisible(self))
}, },
...@@ -353,7 +352,7 @@ Booster <- R6Class( ...@@ -353,7 +352,7 @@ Booster <- R6Class(
lgb.c_str(filename)) lgb.c_str(filename))
# Return self # Return self
return(self) return(invisible(self))
}, },
# Save model to string # Save model to string
...@@ -712,14 +711,14 @@ lgb.load <- function(filename = NULL, model_str = NULL){ ...@@ -712,14 +711,14 @@ lgb.load <- function(filename = NULL, model_str = NULL){
# Return new booster # Return new booster
if (!is.null(filename) && !file.exists(filename)) stop("lgb.load: file does not exist for supplied filename") if (!is.null(filename) && !file.exists(filename)) stop("lgb.load: file does not exist for supplied filename")
if (!is.null(filename)) return(Booster$new(modelfile = filename)) if (!is.null(filename)) return(invisible(Booster$new(modelfile = filename)))
# Load from model_str # Load from model_str
if (!is.null(model_str) && !is.character(model_str)) { if (!is.null(model_str) && !is.character(model_str)) {
stop("lgb.load: model_str should be character") stop("lgb.load: model_str should be character")
} }
# Return new booster # Return new booster
if (!is.null(model_str)) return(Booster$new(model_str = model_str)) if (!is.null(model_str)) return(invisible(Booster$new(model_str = model_str)))
} }
...@@ -769,7 +768,7 @@ lgb.save <- function(booster, filename, num_iteration = NULL){ ...@@ -769,7 +768,7 @@ lgb.save <- function(booster, filename, num_iteration = NULL){
} }
# Store booster # Store booster
booster$save_model(filename, num_iteration) invisible(booster$save_model(filename, num_iteration))
} }
......
...@@ -98,7 +98,7 @@ Dataset <- R6Class( ...@@ -98,7 +98,7 @@ Dataset <- R6Class(
...) ...)
# Return ret # Return ret
return(ret) return(invisible(ret))
}, },
...@@ -107,7 +107,7 @@ Dataset <- R6Class( ...@@ -107,7 +107,7 @@ Dataset <- R6Class(
# Check for handle null # Check for handle null
if (!lgb.is.null.handle(private$handle)) { if (!lgb.is.null.handle(private$handle)) {
return(self) return(invisible(self))
} }
# Get feature names # Get feature names
...@@ -274,8 +274,8 @@ Dataset <- R6Class( ...@@ -274,8 +274,8 @@ Dataset <- R6Class(
stop("lgb.Dataset.construct: label should be set") stop("lgb.Dataset.construct: label should be set")
} }
# Return oneself # Return self
return(self) return(invisible(self))
}, },
...@@ -336,13 +336,13 @@ Dataset <- R6Class( ...@@ -336,13 +336,13 @@ Dataset <- R6Class(
# Check column names non-existence # Check column names non-existence
if (is.null(colnames)) { if (is.null(colnames)) {
return(self) return(invisible(self))
} }
# Check empty column names # Check empty column names
colnames <- as.character(colnames) colnames <- as.character(colnames)
if (length(colnames) == 0) { if (length(colnames) == 0) {
return(self) return(invisible(self))
} }
# Write column names # Write column names
...@@ -359,7 +359,7 @@ Dataset <- R6Class( ...@@ -359,7 +359,7 @@ Dataset <- R6Class(
} }
# Return self # Return self
return(self) return(invisible(self))
}, },
...@@ -446,7 +446,7 @@ Dataset <- R6Class( ...@@ -446,7 +446,7 @@ Dataset <- R6Class(
} }
# Return self # Return self
return(self) return(invisible(self))
}, },
...@@ -472,7 +472,7 @@ Dataset <- R6Class( ...@@ -472,7 +472,7 @@ Dataset <- R6Class(
# Parameter updating # Parameter updating
private$params <- modifyList(private$params, params) private$params <- modifyList(private$params, params)
self return(invisible(self))
}, },
...@@ -481,7 +481,7 @@ Dataset <- R6Class( ...@@ -481,7 +481,7 @@ Dataset <- R6Class(
# Check for identical input # Check for identical input
if (identical(private$categorical_feature, categorical_feature)) { if (identical(private$categorical_feature, categorical_feature)) {
return(self) return(invisible(self))
} }
# Check for empty data # Check for empty data
...@@ -495,7 +495,7 @@ Dataset <- R6Class( ...@@ -495,7 +495,7 @@ Dataset <- R6Class(
# Finalize and return self # Finalize and return self
self$finalize() self$finalize()
return(self) return(invisible(self))
}, },
...@@ -509,7 +509,7 @@ Dataset <- R6Class( ...@@ -509,7 +509,7 @@ Dataset <- R6Class(
# Check for identical references # Check for identical references
if (identical(private$reference, reference)) { if (identical(private$reference, reference)) {
return(self) return(invisible(self))
} }
# Check for empty data # Check for empty data
...@@ -535,7 +535,7 @@ Dataset <- R6Class( ...@@ -535,7 +535,7 @@ Dataset <- R6Class(
# Finalize and return self # Finalize and return self
self$finalize() self$finalize()
return(self) return(invisible(self))
}, },
...@@ -548,7 +548,7 @@ Dataset <- R6Class( ...@@ -548,7 +548,7 @@ Dataset <- R6Class(
ret = NULL, ret = NULL,
private$handle, private$handle,
lgb.c_str(fname)) lgb.c_str(fname))
return(self) return(invisible(self))
} }
), ),
...@@ -580,7 +580,7 @@ Dataset <- R6Class( ...@@ -580,7 +580,7 @@ Dataset <- R6Class(
# Return self is identical predictor # Return self is identical predictor
if (identical(private$predictor, predictor)) { if (identical(private$predictor, predictor)) {
return(self) return(invisible(self))
} }
# Check for empty data # Check for empty data
...@@ -604,7 +604,7 @@ Dataset <- R6Class( ...@@ -604,7 +604,7 @@ Dataset <- R6Class(
# Finalize and return self # Finalize and return self
self$finalize() self$finalize()
return(self) return(invisible(self))
} }
...@@ -649,7 +649,7 @@ lgb.Dataset <- function(data, ...@@ -649,7 +649,7 @@ lgb.Dataset <- function(data,
...) { ...) {
# Create new dataset # Create new dataset
Dataset$new(data, invisible(Dataset$new(data,
params, params,
reference, reference,
colnames, colnames,
...@@ -658,7 +658,7 @@ lgb.Dataset <- function(data, ...@@ -658,7 +658,7 @@ lgb.Dataset <- function(data,
free_raw_data, free_raw_data,
NULL, NULL,
info, info,
...) ...))
} }
...@@ -693,7 +693,7 @@ lgb.Dataset.create.valid <- function(dataset, data, info = list(), ...) { ...@@ -693,7 +693,7 @@ lgb.Dataset.create.valid <- function(dataset, data, info = list(), ...) {
} }
# Create validation dataset # Create validation dataset
dataset$create_valid(data, info, ...) invisible(dataset$create_valid(data, info, ...))
} }
...@@ -719,7 +719,7 @@ lgb.Dataset.construct <- function(dataset) { ...@@ -719,7 +719,7 @@ lgb.Dataset.construct <- function(dataset) {
} }
# Construct the dataset # Construct the dataset
dataset$construct() invisible(dataset$construct())
} }
...@@ -871,7 +871,7 @@ slice.lgb.Dataset <- function(dataset, idxset, ...) { ...@@ -871,7 +871,7 @@ slice.lgb.Dataset <- function(dataset, idxset, ...) {
} }
# Return sliced set # Return sliced set
dataset$slice(idxset, ...) invisible(dataset$slice(idxset, ...))
} }
...@@ -974,7 +974,7 @@ setinfo.lgb.Dataset <- function(dataset, name, info, ...) { ...@@ -974,7 +974,7 @@ setinfo.lgb.Dataset <- function(dataset, name, info, ...) {
} }
# Set information # Set information
dataset$setinfo(name, info) invisible(dataset$setinfo(name, info))
} }
#' Set categorical feature of \code{lgb.Dataset} #' Set categorical feature of \code{lgb.Dataset}
...@@ -1005,7 +1005,7 @@ lgb.Dataset.set.categorical <- function(dataset, categorical_feature) { ...@@ -1005,7 +1005,7 @@ lgb.Dataset.set.categorical <- function(dataset, categorical_feature) {
} }
# Set categoricals # Set categoricals
dataset$set_categorical_feature(categorical_feature) invisible(dataset$set_categorical_feature(categorical_feature))
} }
...@@ -1040,7 +1040,7 @@ lgb.Dataset.set.reference <- function(dataset, reference) { ...@@ -1040,7 +1040,7 @@ lgb.Dataset.set.reference <- function(dataset, reference) {
} }
# Set reference # Set reference
dataset$set_reference(reference) invisible(dataset$set_reference(reference))
} }
#' Save \code{lgb.Dataset} to a binary file #' Save \code{lgb.Dataset} to a binary file
...@@ -1075,5 +1075,5 @@ lgb.Dataset.save <- function(dataset, fname) { ...@@ -1075,5 +1075,5 @@ lgb.Dataset.save <- function(dataset, fname) {
} }
# Store binary # Store binary
dataset$save_binary(fname) invisible(dataset$save_binary(fname))
} }
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