Skip to content
Prev 62277 / 63424 Next

Spurious warning in as.data.frame.factor()

? Tue, 12 Mar 2024 12:33:17 -0700
Herv? Pag?s <hpages.on.github at gmail.com> ?????:
How about something like the following:

Index: src/library/base/R/zzz.R
===================================================================
--- src/library/base/R/zzz.R	(revision 86109)
+++ src/library/base/R/zzz.R	(working copy)
@@ -681,7 +681,14 @@
     bdy <- body(as.data.frame.vector)
     bdy <- bdy[c(1:2, seq_along(bdy)[-1L])] # taking [(1,2,2:n)] to insert at [2]:
     ## deprecation warning only when not called by method dispatch from as.data.frame():
-    bdy[[2L]] <- quote(if((sys.nframe() <= 1L || !identical(sys.function(-1L), as.data.frame)))
+    bdy[[2L]] <- quote(if((sys.nframe() <= 1L || !(
+	identical(sys.function(-1L), as.data.frame) || (
+	    .isMethodsDispatchOn() &&
+	    methods::is(sys.function(-1L), 'derivedDefaultMethod') &&
+	    identical(
+		sys.function(-1L)@generic,
+		structure('as.data.frame', package = 'base')
+	    )))))
 	.Deprecated(
 	    msg = gettextf(
 		"Direct call of '%s()' is deprecated.  Use '%s()' or
 		'%s()' instead",

The patch passes make check-devel, but I'm not sure how to safely put
setGeneric('as.data.frame'); as.data.frame(factor(1:10)) in a
regression test.