Skip to content

Commit

Permalink
Fix R function call in tryXts C function
Browse files Browse the repository at this point in the history
Evaluating the expression created by LCONS() would cause a crash in
RcppXts because the second argument to LCONS should be a pairlist, not
a SEXP. This bug was introducted in the commit that removed the
SET_TYPEOF() calls.
  • Loading branch information
joshuaulrich committed Oct 15, 2024
1 parent 2113fae commit 476225c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions inst/tinytest/test-reclass.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,9 @@ xts_attr <- list("hello" = "world")
xtsAttributes(y) <- xts_attr
z <- reclass(x, y)
expect_equal(xts_attr, xtsAttributes(z), info = info_msg)

# ensure calls to tryXts() C function work
x <- xts(1:3, .Date(1:3))
z <- .Call(xts:::C_tryXts, as.zoo(x))
y <- try.xts(as.zoo(x))
expect_identical(y, z, info = "calls to C_tryXts() call try.xts()")
2 changes: 1 addition & 1 deletion src/tryXts.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ SEXP tryXts (SEXP x)
PROTECT(str_xts = mkString("xts")); P++;
PROTECT(env = R_FindNamespace(str_xts)); P++;

PROTECT(expr = LCONS(install("try.xts"), x)); P++;
PROTECT(expr = lang2(install("try.xts"), x)); P++;
PROTECT(result = eval(expr, env)); P++;

if( !Rf_asInteger(isXts(result)) ) {
Expand Down

0 comments on commit 476225c

Please sign in to comment.