[R] deparse(substitute(x)) on an object with S3 class

Remko Duursma remkoduursma at gmail.com
Thu May 3 12:15:00 CEST 2012


Dear list,


can someone explain to me why deparse(substitute(x)) does not seem to work
when x is of a user-defined S3 class?
In my actual problem, my print method is part of a package, and the method
is registered in the NAMESPACE, if that should make a difference.

> print.testclass <- function(x,...){
  xname <- deparse(substitute(x))
  cat("Your object name is",xname,"\n")
}
 
testlist <- list()
testlist[[1]] <- 1:10
class(testlist) <- "testclass"

# This does not work as expected: 
> testlist
Your object name is structure(list(1:10), class = "testclass") 
 
# But this does :
> testlist2 <- unclass(testlist)
> print.testclass(testlist2)
Your object name is testlist2



thanks,
Remko Duursma


--
View this message in context: http://r.789695.n4.nabble.com/deparse-substitute-x-on-an-object-with-S3-class-tp4605592.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list