Skip to content

Commit 60fce49

Browse files
aitapMichaelChirico
andcommitted
Use Rf_charIsASCII for IS_ASCII instead of testing LEVELS on R >= 4.5 (#6422)
* Drop direct use of LEVELS in R >= 4.5 There's no explicit encoding code for ASCII, so use charIsASCII() ("eapi", expected to appear in R-4.5.0). * fine-tune NEWS * multiple PRs :) * tag SVN revision * TODO * fix merge --------- Co-authored-by: Michael Chirico <[email protected]>
1 parent 8999155 commit 60fce49

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
2. `fread(keepLeadingZeros=TRUE)` now correctly parses dates with leading zeros as dates instead of strings, [#6851](https://github.com/Rdatatable/data.table/issues/6851). Thanks @TurnaevEvgeny for the report and @ben-schwen for the fix.
1010

11+
## NOTES
12+
13+
1. Continued work to remove non-API C functions, [#6180](https://github.com/Rdatatable/data.table/issues/6180). Thanks Ivan Krylov for the PRs and for writing a clear and concise guide about the R API: https://aitap.codeberg.page/R-api/.
14+
1115
# data.table [v1.17.0](https://github.com/Rdatatable/data.table/milestone/34) (20 Feb 2025)
1216

1317
## POTENTIALLY BREAKING CHANGES

src/data.table.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@
4242
/* we mean the encoding bits, not CE_NATIVE in a UTF-8 locale */
4343
#define IS_UTF8(x) (getCharCE(x) == CE_UTF8)
4444
#define IS_LATIN(x) (getCharCE(x) == CE_LATIN1)
45-
#define IS_ASCII(x) (LEVELS(x) & 64) // API expected in R >= 4.5
45+
// TODO: remove the `R_SVN_VERSION` check when R 4.5.0 is released (circa Apr. 2025)
46+
#if R_VERSION < R_Version(4, 5, 0) || R_SVN_REVISION < 86789
47+
# define IS_ASCII(x) (LEVELS(x) & 64)
48+
#else
49+
# define IS_ASCII(x) (Rf_charIsASCII(x)) // no CE_ASCII
50+
#endif
4651
#define IS_TRUE(x) (TYPEOF(x)==LGLSXP && LENGTH(x)==1 && LOGICAL(x)[0]==TRUE)
4752
#define IS_FALSE(x) (TYPEOF(x)==LGLSXP && LENGTH(x)==1 && LOGICAL(x)[0]==FALSE)
4853
#define IS_TRUE_OR_FALSE(x) (TYPEOF(x)==LGLSXP && LENGTH(x)==1 && LOGICAL(x)[0]!=NA_LOGICAL)

0 commit comments

Comments
 (0)