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

GH-15894: Make sure the functions that are supposed to be exported are exported in the R package #15899

Merged
merged 8 commits into from
Nov 10, 2023

Conversation

tomasfryda
Copy link
Contributor

@@ -48,6 +48,10 @@
registerS3method("print", "H2OExplanation", "print.H2OExplanation")
.s3_register("repr", "repr_text", "H2OExplanation")
.s3_register("repr", "repr_html", "H2OExplanation")

# CoxPH
.s3_register("survival", "survfit", "H2OCoxPHModel")
Copy link
Contributor Author

@tomasfryda tomasfryda Nov 3, 2023

Choose a reason for hiding this comment

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

Registering a class with S3 method in one package to a generic from another package is hard in R (unless it's some of the packages that are loaded by default in the package environment (base) - for those we can use the registerS3Method).


# src_path <- paste(h2oRDir,"h2o-package","R",sep=.Platform$file.sep)
# invisible(lapply(to_src,function(x){source(paste(src_path, x, sep = .Platform$file.sep))}))
devtools::load_all(paste(h2oRDir,"h2o-package",sep=.Platform$file.sep), export_all=FALSE)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

export_all = FALSE tells devtools to just export those methods that are supposed to be exported so this helps to find out which methods are not exported but used in the tests.

- h2o.get_predictor_added_per_step
- h2o.get_predictor_removed_per_step
- h2o.get_predictors_added_per_step
- h2o.get_predictors_removed_per_step
Copy link
Contributor Author

Choose a reason for hiding this comment

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

(missing s in predictorS )

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch!

@tomasfryda tomasfryda force-pushed the tomf_GH-15894_export_unexported_in_R branch from ab693b1 to 6cfe711 Compare November 6, 2023 11:04
@tomasfryda tomasfryda marked this pull request as ready for review November 6, 2023 12:30
@tomasfryda tomasfryda marked this pull request as draft November 6, 2023 12:37
@tomasfryda tomasfryda self-assigned this Nov 6, 2023
@@ -113,10 +113,13 @@ function(cur.dir, root, root.parent = NULL) {
default.packages <-
function() {
to_require <- c("jsonlite", "RCurl", "RUnit", "R.utils", "testthat", "ade4", "glmnet", "gbm", "ROCR", "e1071",
"tools", "statmod", "fpc", "cluster")
"tools", "statmod", "fpc", "cluster", "survival")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

for CoxPH tests

invisible(lapply(to_require,function(x){require(x,character.only=TRUE,quietly=TRUE,warn.conflicts=FALSE)}))
invisible(lapply(to_require,function(x) {
if (!require(x,character.only=TRUE,quietly=TRUE,warn.conflicts=FALSE))
warning(paste("Package", x, "is not available."), call. = FALSE)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mainly to make it easier for us to find out why some test might not work. We import packages and if unsuccessful we used to silently fail, after this change we should see that some package is not available (and R names are sometimes quite obscure so it's hard to guess if we are missing a package or badly exporting something or both (survfit.H2OCoxPHModel)).

@tomasfryda tomasfryda marked this pull request as ready for review November 7, 2023 11:59
@tomasfryda
Copy link
Contributor Author

I would like to ask you for a review in your areas:

  • @maurever you seem to be our expert on CoxPH (according to our bus factor) and I think you know TF-IDF implementation.
  • @wendycwong our bus factor table says you are our expert on GRLM and I remember you worked on ModelSelection as well.

@tomasfryda tomasfryda added this to the 3.44.0.3 milestone Nov 7, 2023
.s3_register("survival", "survfit", "H2OCoxPHModel")

# H2OFrame
.s3_register("stats", "median", "H2OFrame")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

stats package is not imported in the package namespace so it has to be specified here.

Confusingly, min, mean, max are defined in base package that is imported so they don't have to be listed here.

maurever
maurever previously approved these changes Nov 8, 2023
Copy link
Contributor

@maurever maurever left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @tomasfryda.

@tomasfryda tomasfryda merged commit 437e432 into rel-3.44.0 Nov 10, 2023
33 checks passed
@tomasfryda tomasfryda deleted the tomf_GH-15894_export_unexported_in_R branch November 10, 2023 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants