checkmate icon indicating copy to clipboard operation
checkmate copied to clipboard

`checkScalar` on POSIXlt is misleading?

Open mmuurr opened this issue 10 years ago • 1 comments

Observe:

 > x <- Sys.time()
 > y <- as.POSIXlt(x)
 > str(x)
  POSIXct[1:1], format: "2016-04-29 11:44:56"
 > str(y)
  POSIXlt[1:1], format: "2016-04-29 11:44:56"
 > checkScalar(x)
 [1] TRUE
 > checkScalar(y)
 [1] "Must be of type 'atomic scalar', not 'POSIXlt'"
 > length(y)
 [1] 1

A single POSIXlt data point is a list in internal storage, but (IMHO) in the example above y should still be treated as a scalar, especially since length(y) == 1 returns TRUE. Perhaps the 'atomic' portion of the test could be relaxed with an argument passed to checkScalar?

Also, this is less a specific request to make any changes, and more a means to document this behavior (which might help future users), so feel free to close without any changes, though any opinions for discussion on the matter would be greatly appreciated :-)

mmuurr avatar Apr 29 '16 17:04 mmuurr

There are strong arguments to not treat POSIXlt as a scalar value, i.e.

> typeof(y)
[1] "list"
> length(y)
[1] 1
> length(unclass(y))
[1] 11
> y[[1]]
[1] 20.55368

I will look into supporting datetime classes for a future release.

mllg avatar Jun 06 '16 09:06 mllg