[R-package] Rename slice() to lgb.slice.Dataset()#6293
[R-package] Rename slice() to lgb.slice.Dataset()#6293jameslamb merged 3 commits intomicrosoft:masterfrom
slice() to lgb.slice.Dataset()#6293Conversation
lgb.slice.Datasetslice() to lgb.slice.Dataset()
jameslamb
left a comment
There was a problem hiding this comment.
Thanks for this!
I'm ok with making this breaking change, given that:
- it's already been merged over in XGBoost (that PR you linked)
{dplyr}is probably much more widely used than{lightgbm}- the use of
::in some R isn't as common as I wish it was 😞 - as far as I can tell from a quick code search,
{lightgbm}'s reverse dependencies on CRAN don't useslice()
For others wondering what specifically "problematic" in this PR description refers to, it's this:
library(lightgbm)
library(dplyr)
# Attaching package: ‘dplyr’
# The following object is masked from ‘package:lightgbm’:
#
# slice
dtrain <- lgb.Dataset(
data = matrix(rnorm(1e5), nrow = 1000)
)
dtrain$construct()
slice(dtrain, 1:5)
# Error in UseMethod("slice") :
# no applicable method for 'slice' applied to an object of class "c('lgb.Dataset', 'R6')"If slice() is called on a Dataset in a session where {dplyr} was attached after {lightgbm}, the {lightgbm} method isn't found and a runtime error occurs. This can be avoided by such code specifying lightgbm::slice().
|
This error in CI is unrelated to these changes: From the combination of actions/checkout#1474 and https://github.com/r-lib/actions/releases, I suspect the root cause is |
|
This pull request has been automatically locked since there has not been any recent activity since it was closed. |
From similar PR in xgboost: dmlc/xgboost#10017
LightGBM registers a generic S3
slicemethod, and defines it for its classlgb.Dataset.This is problematic in R, since a widely used library, {dplyr}, also defines a generic slice method but with a different signature, with implementations for data frames and variants, and extensions like {dbplyr} and similar define it for more object classes based on dplyr's signature.
This PR renames it to
lgb.slice.Dataset, in order to avoid conflicts with other commonly used R frameworks.