diff --git a/NEWS.md b/NEWS.md index 9edb65a03e..71fd76aa65 100644 --- a/NEWS.md +++ b/NEWS.md @@ -105,6 +105,8 @@ unit = "s") 11. `copy()` now overallocates deeply nested lists of `data.table`s, [#4205](https://github.com/Rdatatable/data.table/issues/4205). Thanks to @d-sci for reporting and the PR. +12. `rbindlist` no longer errors when coercing complex vectors to character vectors, [#4202](https://github.com/Rdatatable/data.table/issues/4202). Thanks to @sritchie73 for reporting and the PR. + ## NOTES 0. Retrospective license change permission was sought from and granted by 4 contributors who were missed in [PR#2456](https://github.com/Rdatatable/data.table/pull/2456), [#4140](https://github.com/Rdatatable/data.table/pull/4140). We had used [GitHub's contributor page](https://github.com/Rdatatable/data.table/graphs/contributors) which omits 3 of these due to invalid email addresses, unlike GitLab's contributor page which includes the ids. The 4th omission was a PR to a script which should not have been excluded; a script is code too. We are sorry these contributors were not properly credited before. They have now been added to the contributors list as displayed on CRAN. All the contributors of code to data.table hold its copyright jointly; your contributions belong to you. You contributed to data.table when it had a particular license at that time, and you contributed on that basis. This is why in the last license change, all contributors of code were consulted and each had a veto. diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 609ccaf797..7cc6819e8f 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -16835,3 +16835,14 @@ test(2137.07, TRUE, DT[, all(trunc(hour30, "hours") == as.ITime(c("07:00", "07:0 test(2137.08, TRUE, DT[, all(trunc(hour31, "hours") == as.ITime(c("07:00", "07:00", "08:00", "08:00", "09:00", "09:00", "10:00", "10:00", "11:00")))]) test(2137.09, TRUE, DT[, all(trunc(minute30, "minutes") == as.ITime(c("07:00:00", "07:00:00", "07:01:00", "07:01:00", "07:02:00", "07:02:00", "07:03:00", "07:03:00", "07:04:00")))]) test(2137.10, TRUE, DT[, all(trunc(minute31, "minutes") == as.ITime(c("07:00:00", "07:00:00", "07:01:00", "07:01:00", "07:02:00", "07:02:00", "07:03:00", "07:03:00", "07:04:00")))]) + +# Complex to character conversion in rbindlist, #4202 +A = data.table(A=complex(real = 1:3, imaginary=c(0, -1, 1))) +B = data.table(A=c('qwe', 'asd')) +test(2138.1, rbind(A,B), data.table(A=c(as.character(A$A), B$A))) +A = data.table(A=c(complex(real = 1:3, imaginary=c(0, -1, 1)), NA)) +test(2138.2, rbind(A,B), data.table(A=c(as.character(A$A), B$A))) +A = data.table(A=c(complex(real = 1:3, imaginary=c(0, -1, 1)), NaN)) +test(2138.3, rbind(A,B), data.table(A=c(as.character(A$A), B$A))) +A = data.table(A=as.complex(rep(NA, 5))) +test(2138.4, rbind(A,B), data.table(A=c(as.character(A$A), B$A))) diff --git a/src/data.table.h b/src/data.table.h index f2687f52ea..90ff7fb6fc 100644 --- a/src/data.table.h +++ b/src/data.table.h @@ -47,6 +47,9 @@ typedef R_xlen_t RLEN; #define NA_INTEGER64 INT64_MIN #define MAX_INTEGER64 INT64_MAX +// for use with CPLXSXP, no macro provided by R internals +#define ISNAN_COMPLEX(x) (ISNAN((x).r) || ISNAN((x).i)) // TRUE if either real or imaginary component is NA or NaN + // Backport macros added to R in 2017 so we don't need to update dependency from R 3.0.0 #ifndef MAYBE_SHARED # define MAYBE_SHARED(x) (NAMED(x) > 1) diff --git a/src/utils.c b/src/utils.c index e2c12940ff..87348beb7c 100644 --- a/src/utils.c +++ b/src/utils.c @@ -62,6 +62,13 @@ bool allNA(SEXP x, bool errorForBadType) { } } return true; + case CPLXSXP: { + const Rcomplex *xd = COMPLEX(x); + for (int i=0; i