[R] Problem with S4 generic function print

Sven Laur swen at math.ut.ee
Mon Jan 11 14:47:01 CET 2010


First, if I have an S4 class boo should I define S3 method for  
printing print.boo(..) or should I define S4 method print(..).
I mainly need to define print function only because some user might  
call it and then I would like to dispatch the call to
right function instead.

Second, it seems that by defining S4 generic function print, it is  
possible to break argument hinting on the status bar.
Namely, as I understand, the Mac OS X GUI client makes a call args()  
if something like

letter(

is typed to console. Since letter() function does not exists, it  
should return nothing to the status bar and nothing to
console, as I as a user have not entered any call, yet. However, if S4  
generic print is defined, a mysterious error
message

Error in args(letter) : no function to return from, jumping to top level

appears after typing

letter()

without return('\n') to console. It seems bizarre...

System is

Mac OS X 10.5.8 (PowerPC)
R 2.9.1 GUI 1.28 Tiger build 32-bit (5444)
R version 2.9.1 (2009-06-26)

Minimal amount of code to get the behaviour is

  if(!isGeneric("print")) {setGeneric("print",useAsDefault=print)}

What is the underlying problem?

Sven Laur



More information about the R-help mailing list