[R] signif() generic

ockham@gmx.net ockham at gmx.net
Wed Jan 19 01:49:42 CET 2005


Dear list, 

I'm trying to write a class for Gaussian error propagation of measured
values and their (estimated) errors,

> setClass("sec", representation(val="numeric", err="numeric"))

I've already successfully implemented basic arithmetics using mostly the
"Arith" group generics. But I'm running into trouble when trying to get
signif() to work for my purposes, i.e. with a default argument
(digits=2): When trying 

> seMethod("signif", signature(x="sec", digits="numeric")), 
	function(x, digits=2){
	# ...do something...
	}
)

and 

> signif(sec1)

I get

> Error in signif(x, digits) : Non-numeric argument to mathematical
function

Putting a second argument (like digits=2) into the call makes it work,
but I want some default behavior specified for missing digits argument
so it works in an analogous fashion as signif for numeric values. 
I also tried inserting 

> setGeneric("signif", function(x, digits=6) standardGeneric("signif")) 

before the setMethod block, but that wouldn't help either. I'm pretty
clueless after having studied most of the material in the documentation
of the methods package and single functions concerning generic behavior
-- somehow I don't see what I'm doing wrong. 
Any help would be greatly appreciated,

Greetings, 
Ockham




More information about the R-help mailing list