[R] graphics useRaster check_irregular definition for date or posix

cd@@ek m@iii@g oii posteo@de cd@@ek m@iii@g oii posteo@de
Tue Apr 13 17:11:39 CEST 2021


 Hi

The function `check_irregular()` defined within
`graphics::image.default()` checks if the `useRaster` argument for
`graphics::image()` can be true or must be false. 

According to this function, the following example vector is irregular:
```
time <- seq(as.Date("2020-1-1"), as.Date("2020-12-31"), l=12)
 check_irregular(time, time)
# TRUE
```
In my view, this is not correct. 

In this case, the `all.equal`-call does not evaluate to true due to the
special class of `dx` (or `dy`). If I slightly rewrite the function as
```
my_check_irregular <- function (x, y)
{ 
 dx <- as.numeric(diff(x)) 
 dy <- as.numeric(diff(y)) 
 (length(dx) && !isTRUE(all.equal(dx, rep(dx[1], length(dx))))) || 
 (length(dy) && !isTRUE(all.equal(dy, rep(dy[1], length(dy))))) 
}
 ```
the correct answer is obtained (i.e. that the input vector is not
irregular based on the rational behind `all.equal`):
```
my_check_irregular(time, time) 
# FALSE
 ```

The same applies to POSIX* objects. I was wondering if this is intended
or not?

Thanks a lot for any answer,
Chris 
	[[alternative HTML version deleted]]



More information about the R-help mailing list