Skip to content

Commit d011a89

Browse files
author
maechler
committed
formally deprecate getMethods() [and more cleanup from r86513]
git-svn-id: https://svn.r-project.org/R/trunk@87282 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent ad1792c commit d011a89

File tree

3 files changed

+11
-41
lines changed

3 files changed

+11
-41
lines changed

doc/NEWS.Rd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@
149149
\code{SignatureMethod} were made defunct, as were the
150150
\code{"MethodsList"} branches of functions \code{assignMethodsMetaData},
151151
\code{finalDefaultMethod}, and \code{MethodAddCoerce}.
152+
153+
\item \code{getMethods(*, table=TRUE)} is also deprecated.
152154
}
153155
}
154156

src/library/methods/R/Methods.R

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# File src/library/methods/R/Methods.R
22
# Part of the R package, https://www.R-project.org
33
#
4-
# Copyright (C) 1995-2023 The R Core Team
4+
# Copyright (C) 1995-2024 The R Core Team
55
#
66
# This program is free software; you can redistribute it and/or modify
77
# it under the terms of the GNU General Public License as published by
@@ -17,7 +17,7 @@
1717
# https://www.R-project.org/Licenses/
1818

1919
## copy here to avoid importing from stats and hence loading stats
20-
## namespace when methods if loaded
20+
## namespace when methods is loaded
2121
setNames <- stats::setNames
2222

2323

@@ -351,7 +351,8 @@ getMethods <-
351351
function(f, where = topenv(parent.frame()), table = FALSE)
352352
{
353353
if(!table)
354-
.MlistDefunct("getMethods", "findMethods")
354+
.MlistDefunct("getMethods", "findMethods")
355+
else .Deprecated("getMethodsForDispatch(f, TRUE)")
355356
nowhere <- missing(where)
356357
fdef <- getGeneric(f, where = where)
357358
f <- fdef@generic
@@ -366,41 +367,6 @@ getMethodsForDispatch <- function(fdef, inherited = FALSE)
366367
.getMethodsTable(fdef, environment(fdef), inherited = inherited)
367368
}
368369

369-
## Some functions used in MethodsListSelect, that must be safe against recursive
370-
## method selection.
371-
372-
.setIfBase <- function(f, fdef, mlist) {
373-
if(is.null(f))
374-
FALSE
375-
else {
376-
found <- base::exists(f, "package:base")
377-
if(found) {
378-
## force (default) computation of mlist in MethodsListSelect
379-
base::assign(".Methods", envir = base::environment(fdef),
380-
base::get(f, "package:base"))
381-
}
382-
found
383-
}
384-
}
385-
386-
## Must NOT use the standard version to prevent recursion {still true ?}
387-
.getMethodsForDispatch <- function(fdef) {
388-
ev <- base::environment(fdef)
389-
if(base::exists(".Methods", envir = ev))
390-
base::get(".Methods", envir = ev)
391-
## else NULL
392-
}
393-
394-
.setMethodsForDispatch <- function(f, fdef, mlist) {
395-
ev <- environment(fdef)
396-
if(!is(fdef, "genericFunction") ||
397-
!exists(".Methods", envir = ev, inherits = FALSE))
398-
stop(sprintf("internal error: did not get a valid generic function object for function %s",
399-
sQuote(f)),
400-
domain = NA)
401-
assign(".Methods", envir = ev, mlist)
402-
}
403-
404370
cacheMethod <-
405371
## cache the given definition in the method metadata for f
406372
## Support function: DON'T USE DIRECTLY (does no checking)
@@ -417,6 +383,7 @@ cacheMethod <-
417383
.getMethodsTable(fdef, ev, inherited = TRUE))
418384
}
419385

386+
## for .removeSubClass() and .removeSuperClass():
420387
.removeCachedMethod <- function(f, sig, fdef = getGeneric(f))
421388
cacheMethod(f, sig, NULL, names(sig), fdef)
422389

src/library/methods/man/findMethods.Rd

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
% File src/library/methods/man/findMethods.Rd
22
% Part of the R package, https://www.R-project.org
3-
% Copyright 2008-2019 R Core Team
3+
% Copyright 2008-2024 R Core Team
44
% Distributed under GPL 2 or later
55

66
\name{findMethods}
@@ -39,7 +39,8 @@
3939
function \code{f} in the environment or search position \code{where}
4040
(or for the generic function generally if \code{where} is missing).
4141

42-
The defunct function \code{getMethods} is an older alternative to
42+
The deprecated function \code{getMethods} (defunct for default \code{table=FALSE})
43+
is an older alternative to
4344
\code{findMethods} , returning information in the form of an object of
4445
class \code{MethodsList}, previously used for method dispatch. This
4546
class of objects is deprecated generally and will disappear in a
@@ -54,7 +55,7 @@ findMethodSignatures(..., target = TRUE, methods = )
5455
hasMethods(f, where, package)
5556

5657
## Deprecated in 2010 and defunct in 2015 for 'table = FALSE':
57-
getMethods(f, where, table = FALSE)
58+
getMethods(f, where, table = FALSE) # deprecated -> use getMethodsForDispatch()
5859
}
5960
\arguments{
6061
\item{f}{A generic function or the character-string name of one.}

0 commit comments

Comments
 (0)