Skip to content
Prev 36793 / 63424 Next

possible bug in formals

Dear Brian and Uwe,

Thanks a lot for the clarification.
I made the naive assumption that numeric constants in R are similar to
those in C. 

Two questions still remain:

(1) when I have a function 

    f<- function(a=1,b=-1) { a+b }

    is it safe to use 

    val <- as.character(deparse(formals(f)$b))

    to obtain a string that contains the default value for
    argument "b". (Does is also work for other arguments with some 
    default of arbitrary class?)

(2) I have seen that packages like gWidget (in function ggenericwidget)
    use a statement like

    switch(class(formals(f)$b),
	numeric = { .... },
        character = { .... },
        class = { .... }, ....

    for automatically processing function arguments.
    in the case of "b=-1" this procedure obviously fails.
    (I found this behavior of 'formals' while playing around with 
    packages "gWidgets" and "fgui" from CRAN).

    Is there a safe workaround for this problem?

    That is, is there a safe function that returns class
    "numeric" for an exresion like "-1" or "-Inf"?

Josef
On Sun, May 23, 2010 at 03:52:00PM +0100, Prof Brian Ripley wrote: