Richard.Beare@cmis.csiro.au
2001-May-28 23:49 UTC
[Rd] argument names in generic print functions (PR#955)
Hello, I think this is a bug, although it is possible that I'm doind something silly. I want to be able to determine the argument name for variables passed to a generic print function suppose we have print.foo <- function(x, ...) { nm<-deparse(substitute(x)) cat("param name is ", nm, "\n") } d<-structure(1, class="foo") Under R-1.2.[2,3]> print(d)param name is d> dparam name is structure(1, class = "foo") Under Splus 3.4 the responses are> d<-structure(1, class="foo") > dparam name is d> print(d)param name is d If I'm going about this the wrong way then please let me know. Thanks -- Richard Beare, CSIRO Mathematical & Information Sciences Locked Bag 17, North Ryde, NSW 1670, Australia Phone: +61-2-93253221 (GMT+~10hrs) Fax: +61-2-93253200 Richard.Beare@cmis.csiro.au -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Thomas Lumley
2001-May-29 02:05 UTC
[Rd] argument names in generic print functions (PR#955)
On Tue, 29 May 2001 Richard.Beare@cmis.csiro.au wrote:> Hello, > > I think this is a bug, although it is possible that I'm doind something > silly. > > I want to be able to determine the argument name for variables passed to > a generic print function<snip>> Under R-1.2.[2,3] > > > print(d) > param name is d > > > d > param name is structure(1, class = "foo") > > Under Splus 3.4 the responses are > > > d<-structure(1, class="foo") > > d > param name is d > > print(d) > param name is d > > If I'm going about this the wrong way then please let me know.I don't think there is a right way to do this in R. The read-evaluate-print loop in R prints the *value* of an expression that it evaluates, not the expression itself. This means that your print() function doesn't have any way of knowing what the expression was originally called. You have to use print() explicitly to get the parameter name the way you want. It's not a bug, though it seems to be an incompatibility. -thomas Thomas Lumley Asst. Professor, Biostatistics tlumley@u.washington.edu University of Washington, Seattle -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._