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 lgb.last_error() and LGBM_GetLastError_R() #4344

Merged
merged 1 commit into from
Jun 5, 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
10 changes: 0 additions & 10 deletions R-package/R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@ lgb.is.null.handle <- function(x) {
)
}

# [description] Get the most recent error stored on the C++ side and raise it
# as an R error.
lgb.last_error <- function() {
err_msg <- .Call(
LGBM_GetLastError_R
)
stop("api error: ", err_msg)
return(invisible(NULL))
}

lgb.params2str <- function(params) {

# Check for a list as input
Expand Down
9 changes: 0 additions & 9 deletions R-package/src/lightgbm_R.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@
using LightGBM::Common::Split;
using LightGBM::Log;

SEXP LGBM_GetLastError_R() {
SEXP out;
out = PROTECT(Rf_allocVector(STRSXP, 1));
SET_STRING_ELT(out, 0, Rf_mkChar(LGBM_GetLastError()));
UNPROTECT(1);
return out;
}

SEXP LGBM_HandleIsNull_R(SEXP handle) {
return Rf_ScalarLogical(R_ExternalPtrAddr(handle) == NULL);
}
Expand Down Expand Up @@ -712,7 +704,6 @@ SEXP LGBM_BoosterDumpModel_R(SEXP handle,

// .Call() calls
static const R_CallMethodDef CallEntries[] = {
{"LGBM_GetLastError_R" , (DL_FUNC) &LGBM_GetLastError_R , 0},
{"LGBM_HandleIsNull_R" , (DL_FUNC) &LGBM_HandleIsNull_R , 1},
{"LGBM_DatasetCreateFromFile_R" , (DL_FUNC) &LGBM_DatasetCreateFromFile_R , 3},
{"LGBM_DatasetCreateFromCSC_R" , (DL_FUNC) &LGBM_DatasetCreateFromCSC_R , 8},
Expand Down
6 changes: 0 additions & 6 deletions R-package/src/lightgbm_R.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@
#define R_USE_C99_IN_CXX
#include <Rinternals.h>

/*!
* \brief get string message of the last error
* \return err_msg string with error information
*/
LIGHTGBM_C_EXPORT SEXP LGBM_GetLastError_R();

/*!
* \brief check if an R external pointer (like a Booster or Dataset handle) is a null pointer
* \param handle handle for a Booster, Dataset, or Predictor
Expand Down
24 changes: 0 additions & 24 deletions R-package/tests/testthat/test_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,6 @@ test_that("lgb.params2str() works as expected for a key in params with multiple
)
})

context("lgb.last_error")

test_that("lgb.last_error() throws an error if there are no errors", {
expect_error({
lgb.last_error()
}, regexp = "Everything is fine")
})

test_that("lgb.last_error() correctly returns errors from the C++ side", {
testthat::skip(paste0(
"Skipping this test because it causes valgrind to think "
, "there is a memory leak, and needs to be rethought"
))
data(agaricus.train, package = "lightgbm")
train <- agaricus.train
dvalid1 <- lgb.Dataset(
data = train$data
, label = as.matrix(rnorm(5L))
)
expect_error({
dvalid1$construct()
}, regexp = "[LightGBM] [Fatal] Length of label is not same with #data", fixed = TRUE)
})

context("lgb.check.eval")

test_that("lgb.check.eval works as expected with no metric", {
Expand Down
2 changes: 1 addition & 1 deletion build_r.R
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ writeLines(description_contents, DESCRIPTION_FILE)
# CMake-based builds can't currently use R's builtin routine registration,
# so have to update NAMESPACE manually, with a statement like this:
#
# useDynLib(lib_lightgbm, LGBM_GetLastError_R, LGBM_DatasetCreateFromFile_R, ...)
# useDynLib(lib_lightgbm, LGBM_DatasetCreateFromFile_R, ...)
#
# See https://cran.r-project.org/doc/manuals/r-release/R-exts.html#useDynLib for
# documentation of this approach, where the NAMESPACE file uses a statement like
Expand Down