I have a shinyjs package with show function. Today, the user told me that this creates problems when using S4 objects, because the "print" S4 object uses the show method, which is masked by my package when it is attached.
Example:
library(shinyjs) setClass("testS4Object", representation( ID = "numeric", Name = "character" ), prototype( ID = NA_real_, Name = NA_character_ ) ) x = new("testS4Object") x
An error appears because when we print the value of x , it seems to call show under the scenes, but uses shinyjs::show instead of methods::show . When printing methods::show(x) clearly the problem disappears. But I'm a little confused as to why, by default, the S4 printing system calls show without imposing a namespace - is it not dangerous and not really my package error that this error occurs?
The difficult idea is to have a function with the same name as the function in methods ? I think the S4 system needs to know in order to invoke its own show function or the inherited S4 show function.
EDIT: I asked Hadley what he thinks, and he seems to also think this might be a mistake in R, I emailed r-devel to get their opinion
r s4
Dean attali
source share