No non-missing arguments warning when using min or max in reshape2

You get this warning because the min/max are applied to numeric of length 0 argument.

This reproduces the warning.

min(numeric(0))
[1] Inf
Warning message:
In min(numeric(0)) : no non-missing arguments to min; returning Inf

Note that for mean you don’t get the warning :

mean(numeric(0))
[1] NaN

It is just a warning that don’t have any effect in the computation. You can suppress it using suppressWarnings:

 suppressWarnings(dcast(data=molten.iris,
                  Species~variable,value.var="value",
                  fun.aggregate=min))

EDIT

Above I am just answering the question: What’s the meaning of the warning ? and why we have this min/max and not with mean function. The question why dcast is applying the aggregate function to a vector of length 0, it is just a BUG and you should contact the package maintainer. I think the error comes from plyr::vaggregate function used internally by dcast,

plyr::vaggregate(1:3,1:3,min)
Error in .fun(.value[0], ...) : 
  (converted from warning) no non-missing arguments to min; returning Inf

Specially this line of code:

plyr::vaggregate
function (.value, .group, .fun, ..., .default = NULL, .n = nlevels(.group)) 
{
    ### some lines       
    ....
    ### Here I don't understand the meaning of .value[0]
    ### since vector in R starts from 1 not zeros!!!
    if (is.null(.default)) {
        .default <- .fun(.value[0], ...)
    }
    ## the rest of the function 
    .....
}

Leave a Comment