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] Expand user paths in file names #4687

Merged
merged 1 commit into from
Oct 22, 2021

Conversation

david-cortes
Copy link
Contributor

Many R functions take file paths as inputs, but will not expand paths like ~/myfile, which this PR fixes. It comes without any tests because generating files in the user folder in examples and tests would be against CRAN policies.

Copy link
Collaborator

@jameslamb jameslamb left a comment

Choose a reason for hiding this comment

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

Thanks for doing this! Really nice fix to smooth out a rough edge of the R API.

Noting here the specific errors that users of {lightgbm} versions without this fix might face, so that this can be found from search engines when people encounter those errors, and so that anyone finding this PR from release notes will understand why this change was made.

In all of the cases below, as of latest master (d88b445), {lightgbm} raises an error when using paths with ~ and succeeds when replacing the ~ with an absolute path.

Dataset I/O

library(lightgbm)

data(agaricus.test, package = "lightgbm")
test_data <- agaricus.test$data[1L:100L, ]
test_label <- agaricus.test$label[1L:100L]

dtest1 <- lgb.Dataset(test_data, label = test_label)

ds_file <- "~/lightgbm-data.bin"
lgb.Dataset.save(dtest1, ds_file)

[LightGBM] [Fatal] Cannot write binary data to ~/lightgbm-data.bin
Error in dataset$save_binary(fname = fname) :
Cannot write binary data to ~/lightgbm-data.bin

Booster I/O

library(lightgbm)
data(agaricus.train, package = "lightgbm")
train <- agaricus.train

bst <- lightgbm(
    data = as.matrix(train$data)
    , label = train$label
    , params = list(
        num_leaves = 4L
        , learning_rate = 1.0
        , objective = "binary"
    )
    , nrounds = 2L
    , save_name = "~/lightgbm.model"
)

[LightGBM] [Fatal] Model file ~/lightgbm.model is not available for writes
Error in bst$save_model(filename = save_name) :
Model file ~/lightgbm.model is not available for writes


tests because generating files in the user folder in examples and tests would be against CRAN policies

Makes sense, thanks for noting that explicitly. I ran the code samples above after building {lightgbm} from your branch with the following code.

installing lightgbm from this feature branch
git 

Happy to report that as of the changes in this PR, that code succeeds and has the expected behavior.

Thanks again for the help!

@jameslamb
Copy link
Collaborator

@StrikerRUS I'm going to merge this one.

I think it's a good candidate for a potential 3.3.1 release (since it seems #4674 will probably require such a release) as it improves the usability of the R package in a way that doesn't introduce breaking changes, large new functionality, new dependencies, or substantial risk of submission issues with CRAN.

@jameslamb jameslamb merged commit a2b60e8 into microsoft:master Oct 22, 2021
@StrikerRUS
Copy link
Collaborator

I think it's a good candidate for a potential 3.3.1 release

Absolutely support this idea!

@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.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants