Skip to content

Commit

Permalink
tweak show(<non-syntactic S4generic>), fixing PR#18786 (thanks to Mic…
Browse files Browse the repository at this point in the history
…hael Chirico)

git-svn-id: https://svn.r-project.org/R/trunk@87048 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
smeyer committed Aug 23, 2024
1 parent a51d0b5 commit 4339636
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/library/methods/R/show.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ show <- function(object) showDefault(object)
pkg <- object@package
exported <- pkg == ".GlobalEnv" || isBaseNamespace(ns <- asNamespace(pkg)) ||
nam %in% names(.getNamespaceInfo(ns, "exports"))
showGen <- if(exported) nam # was dQuote(nam, NULL)
else paste(pkg, nam, sep=":::")
qnam <- deparse1(as.name(nam), backtick = TRUE) # was dQuote(nam, NULL)
showGen <- if(exported) qnam else paste(pkg, qnam, sep=":::")
cat("Methods may be defined for arguments: ",
paste0(object@signature, collapse=", "), "\n",
"Use showMethods(", showGen,
Expand Down
4 changes: 4 additions & 0 deletions tests/reg-S4.R
Original file line number Diff line number Diff line change
Expand Up @@ -888,3 +888,7 @@ setClass("foo")
sealClass("foo") # failed in R < 4.5.0
stopifnot(isSealedClass("foo"))
stopifnot(removeClass("foo"))


## show(<non-syntactic name>) should recommend backticks for showMethods()
stopifnot(any(grepl("showMethods(`body<-`)", capture.output(show(`body<-`)), fixed=TRUE)))
4 changes: 4 additions & 0 deletions tests/reg-S4.Rout.save
Original file line number Diff line number Diff line change
Expand Up @@ -1187,3 +1187,7 @@ class(from) <- "foo"
> stopifnot(isSealedClass("foo"))
> stopifnot(removeClass("foo"))
>
>
> ## show(<non-syntactic name>) should recommend backticks for showMethods()
> stopifnot(any(grepl("showMethods(`body<-`)", capture.output(show(`body<-`)), fixed=TRUE)))
>

0 comments on commit 4339636

Please sign in to comment.