Skip to content

Commit 3713345

Browse files
author
maechler
committed
isGeneric(fdef=*) fix + documentation
git-svn-id: https://svn.r-project.org/R/trunk@87383 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 4b171f6 commit 3713345

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

doc/NEWS.Rd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,9 @@
392392
integer value. Newly, values outside the range -9 .. 9999 are warned
393393
about and set to a respective boundary or to the default \code{0},
394394
e.g., in case of an \code{NA}.
395+
396+
\item \code{isGeneric(fdef = print)} now works, fixing \PR{18369} thanks to
397+
\I{Mikael Jagan}.
395398
}
396399
}
397400
}

src/library/methods/R/Methods.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,10 @@ isGeneric <-
273273
if(is.null(fdef))
274274
return(FALSE)
275275
## check primitives. These are never found as explicit generic functions.
276-
if(isBaseFun(fdef)) {
277-
if(is.character(f) && f %in% "as.double") f <- "as.numeric"
276+
if(is.primitive(fdef)) {
278277
## the definition of isGeneric() for a base function is that methods are defined
279278
## (other than the default primitive)
280-
gen <- genericForBasic(f, mustFind = FALSE)
279+
gen <- genericForBasic(.primname(fdef), mustFind = FALSE)
281280
return(is.function(gen) && length(names(.getMethodsTable(gen))) > 1L)
282281
}
283282
if(!is(fdef, "genericFunction"))

src/library/methods/man/GenericFunctions.Rd

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ getGenerics(where, searchForm = FALSE)
4242
\section{Summary of Functions}{
4343
\describe{
4444
\item{\code{isGeneric}:}{
45-
Is there a function named \code{f}, and if so, is it a generic?
45+
If \code{fdef} is \code{NULL}, then test if there is a formal
46+
generic function named \code{f} in the current search path or in
47+
the position specified by \code{where}.
48+
49+
If \code{fdef} is non-\code{NULL}, then test if it is a formal
50+
generic function, with name matching \code{f} if \code{f} is not
51+
missing.
4652

4753
The \code{getName} argument allows a function to find the name
4854
from a function definition. If it is \code{TRUE} then the name of
@@ -51,14 +57,12 @@ getGenerics(where, searchForm = FALSE)
5157

5258
The behavior of \code{isGeneric} and \code{\link{getGeneric}} for
5359
primitive functions is slightly different. These functions don't
54-
exist as formal function objects (for efficiency and historical
55-
reasons), regardless of whether methods have been defined for
56-
them. A call to \code{isGeneric} tells you whether methods have
57-
been defined for this primitive function, anywhere in the current
58-
search list, or in the specified position \code{where}. In
59-
contrast, a call to \code{\link{getGeneric}} will return what the
60-
generic for that function would be, even if no methods have been
61-
currently defined for it.
60+
exist as formal generic function objects (for efficiency and
61+
historical reasons), regardless of whether methods have been
62+
defined for them. For a primitive function, \code{isGeneric}
63+
tests whether non-default methods have been defined, whereas
64+
\code{\link{getGeneric}} returns what the formal generic function
65+
object would be, even if no methods have been defined.
6266
}
6367
6468
\item{\code{removeGeneric}, \code{removeMethods}:}{

tests/reg-tests-1e.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,7 @@ stopifnot(exprs = {
16011601

16021602
## options(scipen = <invalid>)
16031603
scipenO <- getOption("scipen")
1604-
assertErrV(options(scipen = NULL))# would work (but ..) in R <= 4.2.2
1604+
assertErrV(options(scipen = NULL))# would work (but ..) in R <= 4.4.2
16051605
assertErrV(options(scipen = 1:2)) # would just work
16061606
assertErrV(options(scipen = 1e99))# would "work" w/ 2 warnings and invalid setting
16071607
stopifnot(identical(getOption("scipen"), scipenO))# unchanged
@@ -1612,6 +1612,11 @@ stopifnot(identical(getOption("scipen"), 9999L))
16121612
## setting to NULL would invalidate as.character(Sys.time())
16131613

16141614

1615+
## PR#18369 (patch by Mikael Jagan)
1616+
stopifnot(!isGeneric(fdef = print), !isGeneric(fdef = c), isGeneric(fdef = show))
1617+
## gave Error argument "f" is missing ... in R <= 4.4.2
1618+
1619+
16151620

16161621
## keep at end
16171622
rbind(last = proc.time() - .pt,

0 commit comments

Comments
 (0)