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

Update checkS3methods to ignore deprecated/defunct functions #76

Open
hturner opened this issue Nov 8, 2024 · 4 comments
Open

Update checkS3methods to ignore deprecated/defunct functions #76

hturner opened this issue Nov 8, 2024 · 4 comments
Assignees
Labels
LatinR 2024 Misc Issues that cannot be classified otherwise needs patch Implement the agreed fix and prepare a patch for review R Issue should require knowledge of R only

Comments

@hturner
Copy link
Member

hturner commented Nov 8, 2024

This task is to update tools::checkS3methods(), so that ignores functions where there is a call to .Deprecated() or .Defunct() in the body of a function.

This will enable a more elegant approach to fixing packages that have functions that look like S3 methods, as discussed on the CRAN Cookbook repo. This approach has the support of Kurt Hornik from the CRAN team.

tools::checkS3methods() is a pure R function, but it is a long function! So part of the task will be working through the code to understand how it could be adapted to only check functions that are not deprecated or defunct, then working on the code to implement the change.

@hturner hturner added needs patch Implement the agreed fix and prepare a patch for review Misc Issues that cannot be classified otherwise LatinR 2024 R Issue should require knowledge of R only labels Nov 8, 2024
@hturner hturner changed the title Update checkS3methods to ignore depracated/defunct functions Update checkS3methods to ignore deprecated/defunct functions Nov 8, 2024
@luciorq
Copy link

luciorq commented Nov 20, 2024

Work from today’s and yesterday’s sessions, under the guidance of @gmbecker and @lawremi, is summarized in Pull Request r-devel/r-svn#188.

Code changes were tested within the Ubuntu-based development container, while CI checks are currently in progress GH actions CI.

To the best of my knowledge, no Bugzilla issue has been opened for this yet. I am still waiting for my R Bugzilla account to be provisioned.

@luciorq
Copy link

luciorq commented Nov 20, 2024

Also find the SVN Diff file:

Index: src/library/tools/R/QC.R
===================================================================
--- src/library/tools/R/QC.R	(revision 87348)
+++ src/library/tools/R/QC.R	(working copy)
@@ -2379,6 +2379,38 @@
    res
 }
 
+### Additional functions for checkS3methods
+checkTopLevelCall <- function(expr, fun_name) {
+  if (inherits(expr, "if") || !is.call(expr)) {
+    return(FALSE)
+  }
+  fun_name <- as.name(fun_name)
+  fun_called <- expr[[1]]
+  if (is.call(fun_called)) {
+    inner_called <- fun_called[[1]]
+    if (as.character(inner_called) %in% c(":::", "::")) {
+      fun_called <- fun_called[[3]]
+    }
+  }
+  identical(fun_called, fun_name)
+}
+
+containsTopLevelCall <- function(x, fun_name) {
+  fun_body <- body(x)
+  if (inherits(fun_body, "{")) {
+    any(vapply(fun_body, checkTopLevelCall, TRUE, fun = fun_name))
+  } else {
+    checkTopLevelCall(fun_body, fun_name)
+  }
+}
+
+isDeprecated <- function(fun) {
+  containsTopLevelCall(fun, quote(.Deprecated))
+}
+isDefunct <- function(fun) {
+  containsTopLevelCall(fun, quote(.Defunct))
+}
+
 ### * checkS3methods
 
 checkS3methods <-
@@ -2603,6 +2635,11 @@
                   function(g) {
                       methods <-
                           gen_dot_cls_matches(g, functions_in_code)
+                      method_funs <-
+                          Filter(Negate(
+                              function(x) isDefunct(x) || isDeprecated(x)
+                              ), mget(methods, code_env))
+                      methods <- names(method_funs)
                       if((n <- length(methods)) > 0L) {
                           gargs <- nfg(g, code_env)
                           entries <-

@hturner
Copy link
Member Author

hturner commented Nov 20, 2024

I discussed this issue with Kurt Hornik directly - I'll ask how he would prefer to receive the patch (maybe he will just pick it up from here).

@hturner
Copy link
Member Author

hturner commented Nov 22, 2024

Feedback from Kurt:

Thanks.  I'll have a look, but I need to take a closer look to ensure
that we're get()ting functions only once, as this is slow.

(Ideally such patches would have some comments in the code explaining
what is going on.)

So I think he is happy to pick it up from here, but you / @lawremi / @gmbecker might want to follow up on his feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LatinR 2024 Misc Issues that cannot be classified otherwise needs patch Implement the agreed fix and prepare a patch for review R Issue should require knowledge of R only
Projects
None yet
Development

No branches or pull requests

4 participants