diff --git a/src/library/methods/R/show.R b/src/library/methods/R/show.R index 9bba1b3707..e6364ec652 100644 --- a/src/library/methods/R/show.R +++ b/src/library/methods/R/show.R @@ -109,6 +109,7 @@ show <- function(object) showDefault(object) nam %in% names(.getNamespaceInfo(ns, "exports")) showGen <- if(exported) nam # was dQuote(nam, NULL) else paste(pkg, nam, sep=":::") + if (make.names(showGen) != showGen) showGen <- paste0("`", showGen, "`") cat("Methods may be defined for arguments: ", paste0(object@signature, collapse=", "), "\n", "Use showMethods(", showGen, diff --git a/tests/reg-S4.R b/tests/reg-S4.R index f1ca099a2d..fe17b9c0a2 100644 --- a/tests/reg-S4.R +++ b/tests/reg-S4.R @@ -888,3 +888,6 @@ setClass("foo") sealClass("foo") # failed in R < 4.5.0 stopifnot(isSealedClass("foo")) stopifnot(removeClass("foo")) + +# show() should recommend backticks for showMethods() +stopifnot(any(grepl("showMethods(`body<-`)", capture.output(show(`body<-`)), fixed=TRUE))) diff --git a/tests/reg-S4.Rout.save b/tests/reg-S4.Rout.save index eba98ed377..da2704763c 100644 --- a/tests/reg-S4.Rout.save +++ b/tests/reg-S4.Rout.save @@ -1187,3 +1187,6 @@ class(from) <- "foo" > stopifnot(isSealedClass("foo")) > stopifnot(removeClass("foo")) > +> # show() should recommend backticks for showMethods() +> stopifnot(any(grepl("showMethods(`body<-`)", capture.output(show(`body<-`)), fixed=TRUE))) +>