[S] printing the name and value of an object (contribution)

Mary Lindstrom (lindstro@biostat.wisc.edu)
Tue, 24 Mar 1998 09:50:58 -0600


This is so simple that I hesitate to contribute it. However, it's
something I use constantly when I want to monitor the values of
variables from within software that I'm developing.

the call

nprint(varname[1:10])

replaces

print("varname[1:10]")
print(varname[1:10])

the "n" in nprint stands for "named"

nprint <- function(x, digits)
{
## prints out the name of the first argument and it's value
## and (optionally) rounds the value.
##
## bugs:
## will bomb if the digits argument is used and x cannot be
## coerced into numeric
##
if(!missing(digits))
x <- round(x, digits)
print(match.call()[[2]])
print(x)
invisible()
}

- Mary
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news