Bug 14468 - Pretty function returning error when only no finite items are passed
Pretty function returning error when only no finite items are passed
Status: RESOLVED FIXED
Product: R
Classification: Unclassified
Component: Language
R 2.12.1
All All
: P5 enhancement
Assigned To: R-core
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-12-24 17:00 UTC by Giuseppe Rumi
Modified: 2010-12-27 15:51 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Giuseppe Rumi 2010-12-24 17:00:29 UTC
Pretty(x) is returning errors when x contains only non-finite items. 

Quoting from help:
"pretty ignores non-finite values in x"

> pretty(c(NA))
Error in pretty.default(c(NA)) : 
  NA/NaN/Inf in foreign function call (arg 1)
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf

> pretty(c(Inf))
Error in pretty.default(c(Inf)) : 
  NA/NaN/Inf in foreign function call (arg 1)
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf

However: 
> pretty(c())
numeric(0)

I would have expected "numeric(0)" returned in all the 3 cases.

To fix it, I would modify the order of few statements in pretty.default() method.

Today it is:

    x <- as.numeric(x)
    if (length(x) == 0L) 
        return(x)
    x <- x[is.finite(x)]
....

I would change to:

    x <- as.numeric(x)
    x <- x[is.finite(x)]
    if (length(x) == 0L) 
        return(x)
....

Regards

Giuseppe
Comment 1 Martin Maechler 2010-12-27 15:51:32 UTC
Thank you, you are right.  
Fixed for R-devel and R "2.12.1 patched".