Skip to content

argument names in generic print functions (PR#955)

2 messages · Richard Beare, Thomas Lumley

#
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]
param name is  d
param name is  structure(1, class = "foo") 


Under Splus 3.4 the responses are
param name is  d
param name is  d 


If I'm going about this the wrong way then please let me know.

Thanks
#
On Tue, 29 May 2001 Richard.Beare@cmis.csiro.au wrote:

            
<snip>
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._