Skip to content

Commit

Permalink
[R-package] Use R standard routines to access character data in C++ (#…
Browse files Browse the repository at this point in the history
…4252)

* converted LGBM_BoosterSaveModel_R

* switch all other non-params cases

* handle params
  • Loading branch information
jameslamb authored May 4, 2021
1 parent d511f1a commit ec87432
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 89 deletions.
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

0 comments on commit ec87432

Please sign in to comment.