Skip to content
Prev 316062 / 398502 Next

functions as arguments to ther functions with inlinedocs

On 24/01/2013 1:32 PM, Jannis wrote:
The definition above is not syntactically correct, it has an extra 
closing paren on the first line.  This would be correct:

dummyfunction = function(filters = function(x) {b = 0; x > b} )
{
    # rest of code here
    return(filters)
}

If that still confuses inlinedocs, then it's a bug in that package. This 
might be easier for it to handle:


dummyfunction = function(filters)
{
    if (missing(filters)) filters <- function(x) {b = 0; x > b}
    # rest of code here
    return(filters)
}


and it should be equivalent to the original.
That's a pretty strange definition.  I would have written it as

dummyfunction = function(filters = b) {
{   a = 1
     b > a
     b
     print('test')
}

Remember that defaults for function arguments are evaluated in the evaluation frame of the function, not
in the caller's evaluation frame, so they don't need to exist when you enter the function, only when you first use the associated argument.

Duncan Murdoch