Java Mailing List Archive

http://www.r-help.com/

Home » R Help for Statistical Computing »

[R] Using substitute in a print method

Chris Stubben

2010-03-19


Author LoginPost Reply

I've defined a new class for some really large tables, and I'd like to use
substitute() in the print function. For example, if I define a new class
below and create a print method for it, I can't figure out how to return the
object name by just typing "d".

d<-diag(2)
class(d)<-c("diag")
print.diag<-function(x,...)
{
  # do something then
  print(paste( "A diagonal matrix", substitute(x)) )
}

> d
[1] "A diagonal matrix 1" "A diagonal matrix 0" "A diagonal matrix 0" "A
diagonal matrix 1"

## This prints what I'd want, but I'm not sure why its different.
print.diag(d)
[1] "A diagonal matrix d"

Thanks for any help,

Chris Stubben

--
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@(protected)
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
©2008 r-help.com - Jax Systems, LLC, U.S.A.