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] factor out lgb.check.r6.class() #4343

Merged
merged 3 commits into from
Jun 5, 2021
Merged

[R-package] factor out lgb.check.r6.class() #4343

merged 3 commits into from
Jun 5, 2021

Conversation

jameslamb
Copy link
Collaborator

The R package has many places where it needs to check that an object is a special LightGBM R6 class (lgb.Booster, lgb.Dataset, or lgb.Predictor). Today, it is inconsistent in the way that it does this. Some code uses special functions like lgb.is.Booster() which call a one-line utility function lgb.check.r6.class(). Other code calls lgb.check.r6.class().

This code proposes factoring out lgb.check.r6.class() completely. I think this has the following benefits:

  • removes a layer of indirection / opportunity for inconsistency
  • makes the code easier to read and understand
# before
if (!lgb.check.r6.class(object = train_set, name = "lgb.Dataset"))

# after
if (!lgb.is.Dataset(train_set))

Since what lgb.check.r6.class() does is so simple, I think that the added indirection it introduces is not worth it, and that the R package's code will be a bit simpler as a result of this change.

Copy link
Collaborator

@StrikerRUS StrikerRUS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jameslamb jameslamb merged commit 4ccf92b into master Jun 5, 2021
@jameslamb jameslamb deleted the r/simplify branch June 5, 2021 17:00
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants