joshuaulrich / xts

Extensible time series class that provides uniform handling of many R time series classes by extending zoo.
http://joshuaulrich.github.io/xts/
GNU General Public License v2.0
219 stars 70 forks source link

SET_TYPEOF() cannot convert REAL to INTEGER in merge #419

Closed joshuaulrich closed 1 month ago

joshuaulrich commented 1 month ago

Description

This test fails in R-devel r86639:

x <- .xts(integer(), integer(), tclass = "Date", tzone = "UTC")
merge(x, x, x)
## Error in merge.xts(x, x, x) : can't change type from REALSXP to INTSXP
## Calls: merge -> merge.xts

Because of the call to SET_TYPEOF() here: https://github.com/joshuaulrich/xts/blob/54298450933fe1d63f221d38afe5aa765849a34b/src/merge.c#L375

That code block calls xts(), which returns an empty xts object with 'double' coredata. SET_TYPEOF() tries to convert it to the same type as x (integer) and that fails.

Thanks to Kurt Hornik for the report.