-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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] Add explicit return statement to R functions. #3703
Conversation
The commits have passed all the tests on my laptop but failed many GitHub Actions checks. Do you know why? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks very much! I think it's ok to proceed with this, since #3352 has been open for a few months. @Juniper-23 I hope you'll come back to LightGBM and contribute when you have time!
There may be some code formatting issues in this PR though. I found two formatting styles in the original files when the code in
return()
is long
Thanks for identifying this inconsistency. I prefer this style:
return(
lgb.call(
fun_name = "LGBM_BoosterGetCurrentIteration_R"
, ret = cur_iter
, private$handle
)
)
Could you please do that for any of the multi-line return statements you see? Both those this PR touches and any that currently exist in the package with the other style like return(lgb.call(...
.
Could you please also add return()
statements to these calls?
build_r.R
:.handle_result()
should havereturn(invisible(NULL))
lgb.plot.interpretation.R
lgb.plot.interpretation()
should havereturn(invisible(NULL))
The commits have passed all the tests on my laptop but failed many GitHub Actions checks. Do you know why?
This is coming from R CMD check
. It looks like somewhere in this PR, you have a typo and accidentally typed inivisible
instead of invisible
.
* checking R code for possible problems ... � � NOTE
cb.reset.parameters : init: no visible global function definition for
‘inivisble’
Undefined global functions or variables:
inivisble
You can find this by clicking "details" on any of the failed builds below, which will take you to the logs: https://github.com/microsoft/LightGBM/pull/3703/checks?check_run_id=1633145099.
You can reproduce this locally too:
sh build-cran-package.sh
R CMD check lightgbm_*.tar.gz --as-cran
The unit tests passing but these checks failing proobably means that this typo occurred in a place that isn't covered by {lightgbm}
's unit tests yet.
@@ -77,6 +79,8 @@ saveRDS.lgb.Booster <- function(object, | |||
, refhook = refhook | |||
) | |||
|
|||
return(invisible(NULL)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of doing this, can you please just add a single return(invisible(NULL))
outside of the if-else block?
Adding these modifications results in many GitHub Action failures. Judging from the log messages, it seems that the failures are caused by unit tests:
However, when I run
This is confusing, and I can't find the failed tests in |
I just realized that you have merged #3662, which contains the failed tests, into |
CI runs against the merger of your PR and its target branch (in this case
This is the behavior of most CI services, and it's done to test that This is also buried deep in the
So those build failures are desirable. They're telling us that CI would start to fail if we merged this PR into Please merge |
@@ -97,13 +99,15 @@ cb.reset.parameters <- function(new_params) { | |||
if (!is.null(env$model)) { | |||
env$model$reset_parameter(params = pars) | |||
} | |||
|
|||
return(invisible(NULL)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this place MIGHT be related to the test failures you saw. env$model$reset_parameter(params = pars)
returns a Booster
, so the current behavior of this function is that that booster is returned if this code runs:
if (!is.null(env$model)) {
env$model$reset_parameter(params = pars)
}
This return(invisible(NULL))
is correct, but please also add a return()
inside that if statement above.
This kind of thing is why this PR is so valuable! To find places like this where {lightgbm}
functions' return values are non-obvious. So thank you!
It turns out that the test failures were caused by a misplaced |
Thanks for the changes @zenggyu . Can you please update to To replicate the linting errors you're facing on Travis, you can run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, thanks so much for contributing!
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. |
Closes #3352.
Hi, @jameslamb and @Juniper-23 , and happy new year!
I noticed that the issue has been opened for quite some time and is still not fixed, so I thought I'd give it a try. You may want to merge this PR in case @Juniper-23 does not have time to create one.
There may be some code formatting issues in this PR though. I found two formatting styles in the original files when the code in
return()
is long (e.g., exceeding 80 characters), for example:Tell me which one you prefer and I'll be happy to make a few more edits!