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] Use R standard routines to access character data in C++ #4252

Merged
merged 3 commits into from
May 4, 2021
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
6 changes: 3 additions & 3 deletions R-package/R/lgb.Booster.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Booster <- R6::R6Class(
# Create booster from model
.Call(
LGBM_BoosterCreateFromModelfile_R
, lgb.c_str(x = modelfile)
, modelfile
, handle
)

Expand All @@ -104,7 +104,7 @@ Booster <- R6::R6Class(
# Create booster from model
.Call(
LGBM_BoosterLoadModelFromString_R
, lgb.c_str(x = model_str)
, model_str
, handle
)

Expand Down Expand Up @@ -452,7 +452,7 @@ Booster <- R6::R6Class(
, private$handle
, as.integer(num_iteration)
, as.integer(feature_importance_type)
, lgb.c_str(x = filename)
, filename
)

return(invisible(self))
Expand Down
12 changes: 6 additions & 6 deletions R-package/R/lgb.Dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ Dataset <- R6::R6Class(

.Call(
LGBM_DatasetCreateFromFile_R
, lgb.c_str(x = private$raw_data)
, private$raw_data
, params_str
, ref_handle
, handle
Expand Down Expand Up @@ -436,7 +436,7 @@ Dataset <- R6::R6Class(
.Call(
LGBM_DatasetSetFeatureNames_R
, private$handle
, lgb.c_str(x = merged_name)
, merged_name
)

}
Expand Down Expand Up @@ -468,7 +468,7 @@ Dataset <- R6::R6Class(
.Call(
LGBM_DatasetGetFieldSize_R
, private$handle
, lgb.c_str(x = name)
, name
, info_len
)

Expand All @@ -486,7 +486,7 @@ Dataset <- R6::R6Class(
.Call(
LGBM_DatasetGetField_R
, private$handle
, lgb.c_str(x = name)
, name
, ret
)

Expand Down Expand Up @@ -527,7 +527,7 @@ Dataset <- R6::R6Class(
.Call(
LGBM_DatasetSetField_R
, private$handle
, lgb.c_str(x = name)
, name
, info
, length(info)
)
Expand Down Expand Up @@ -678,7 +678,7 @@ Dataset <- R6::R6Class(
.Call(
LGBM_DatasetSaveBinary_R
, private$handle
, lgb.c_str(x = fname)
, fname
)
return(invisible(self))
}
Expand Down
4 changes: 2 additions & 2 deletions R-package/R/lgb.Predictor.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Predictor <- R6::R6Class(
# Create handle on it
.Call(
LGBM_BoosterCreateFromModelfile_R
, lgb.c_str(x = modelfile)
, modelfile
, handle
)
private$need_free_handle <- TRUE
Expand Down Expand Up @@ -117,7 +117,7 @@ Predictor <- R6::R6Class(
, as.integer(start_iteration)
, as.integer(num_iteration)
, private$params
, lgb.c_str(x = tmp_filename)
, tmp_filename
)

# Get predictions from file
Expand Down
11 changes: 2 additions & 9 deletions R-package/R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ lgb.params2str <- function(params, ...) {

# Check ret length
if (length(ret) == 0L) {
return(lgb.c_str(x = ""))
return("")
}

return(lgb.c_str(x = paste0(ret, collapse = " ")))
return(paste0(ret, collapse = " "))

}

Expand Down Expand Up @@ -154,13 +154,6 @@ lgb.check_interaction_constraints <- function(interaction_constraints, column_na

}

lgb.c_str <- function(x) {

ret <- charToRaw(as.character(x))
ret <- c(ret, as.raw(0L))
return(ret)

}

lgb.check.r6.class <- function(object, name) {

Expand Down
Loading