Skip to content

Commit

Permalink
Do not use SET_TYPEOF()
Browse files Browse the repository at this point in the history
In R-devel r86639 SET_TYPEOF() errors if you try to convert a REAL to
and INTEGER. Create the xts object without using SET_TYPEOF().

Fixes #419.
  • Loading branch information
joshuaulrich committed Jun 3, 2024
1 parent 2ede2ae commit e3a5862
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
1 change: 0 additions & 1 deletion inst/tinytest/test-merge.R
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ empty_with_dims_3x <-
structure(integer(0), dim = c(0L, 9L), index = .index(x0),
dimnames = list(NULL, c("a", "b", "c", "a.1", "b.1", "c.1", "a.2", "b.2", "c.2")),
class = c("xts", "zoo"))
storage.mode(.index(empty_with_dims_3x)) <- "integer" ## FIXME: this should be 'numeric
expect_identical(xm6, empty_with_dims_3x, info = "merge.xts([empty_xts_with_dims 3x]) has correct dims")


Expand Down
23 changes: 15 additions & 8 deletions src/merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,22 @@ SEXP do_merge_xts (SEXP x, SEXP y,
/* do the inputs have any data to merge? */
len = nrx + nry;
if (len < 1 && ncx < 1 && ncy < 1) {
/* nothing to do, return empty xts object */
SEXP s, t;
PROTECT(s = t = allocList(1)); p++;
SET_TYPEOF(s, LANGSXP);
SETCAR(t, install("xts"));
SEXP out = PROTECT(eval(s, env)); p++;
SET_TYPEOF(out, TYPEOF(x));

/* return empty xts object if there are no rows or columns */
PROTECT(result = allocVector(TYPEOF(x), 0)); p++;
PROTECT(index = allocVector(TYPEOF(xindex), 0)); p++;
setAttrib(index, xts_IndexTzoneSymbol, getAttrib(xindex, xts_IndexTzoneSymbol));
setAttrib(index, xts_IndexTclassSymbol, getAttrib(xindex, xts_IndexTclassSymbol));
setAttrib(index, xts_IndexTformatSymbol, getAttrib(xindex, xts_IndexTformatSymbol));
setAttrib(result, xts_IndexSymbol, index);

if (LOGICAL(retclass)[0]) {
setAttrib(result, R_ClassSymbol, getAttrib(x, R_ClassSymbol));
}
setAttrib(result, xts_ClassSymbol, getAttrib(x, xts_ClassSymbol));

UNPROTECT(p);
return out;
return result;
}

/* Ensure both indexes are REAL if they are not the same type. */
Expand Down

0 comments on commit e3a5862

Please sign in to comment.