The Wayback Machine - https://web.archive.org/web/20200912132014/https://github.com/microsoft/LightGBM/issues/3352
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] All functions should have explicit return statements #3352

Open
jameslamb opened this issue Sep 4, 2020 · 3 comments
Open

[R-package] All functions should have explicit return statements #3352

jameslamb opened this issue Sep 4, 2020 · 3 comments

Comments

@jameslamb
Copy link
Collaborator

@jameslamb jameslamb commented Sep 4, 2020

Summary

In R, the return statement is not strictly required in functions.

# this returns NULL
gives_nothing <- function(x, y){
    print(x)
    print(y)
}

# this returns the value of n
gives_sum <- function(x, y){
    n <- x + y
    n
}

This means that it can sometimes be difficult to understand, from looking at the code, what a function will return.

How to close this issue

To close this issue, make sure that every function in the R package is explicitly using a return statement. The R package's code can all be found in R-package/R.

For functions which look like they should not return anything, please add a new statement at the end:

    return(invisible(NULL))

How this improves LightGBM

This fix will make the R package a little bit more explicit, reducing the risk of mistakes during future development.

@Juniper-23
Copy link
Contributor

@Juniper-23 Juniper-23 commented Sep 9, 2020

I am fairly new to R but with whatever I have learnt so far I believe I can be of some help here :)

@jameslamb
Copy link
Collaborator Author

@jameslamb jameslamb commented Sep 9, 2020

thanks @Juniper-23 ! I just assigned this to you so no one else will take it. It's not urgent so take your time. Let me know if you have any questions.

@Juniper-23
Copy link
Contributor

@Juniper-23 Juniper-23 commented Sep 11, 2020

@jameslamb Thanks! This would help :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.