Re: [Rd] table() and as.character() performance for logical values

2025-04-14 Thread Martin Maechler
> Suharto Anggono Suharto Anggono > on Sat, 12 Apr 2025 08:27:26 + (UTC) writes: > For NA case (x == NA_LOGICAL), if R_print.na_width > NB-1 , the "fast path" for 'EncodeLogical' that I propose previously behaves differently from the general case that truncates at (NB-1). Y

Re: [Rd] table() and as.character() performance for logical values

2025-04-12 Thread Suharto Anggono Suharto Anggono via R-devel
For NA case (x == NA_LOGICAL), if R_print.na_width > NB-1 , the "fast path" for 'EncodeLogical' that I propose previously behaves differently from the general case that truncates at (NB-1). To be consistent with the general case, if(w == R_print.na_width) can be replaced with if(w == R_print.na_

Re: [Rd] table() and as.character() performance for logical values

2025-04-11 Thread Tomas Kalibera
On 4/11/25 16:23, Suharto Anggono Suharto Anggono via R-devel wrote: Alternative revision: Added to my changed 'StringFromLogical': #define CACHE 16 if (!(*warn & CACHE)) {TrueCh = FalseCh = NULL; *warn |= CACHE;} No change to 'coerceToString' and 'coerceToSymbol'. -- On Friday

Re: [Rd] table() and as.character() performance for logical values

2025-04-11 Thread Suharto Anggono Suharto Anggono via R-devel
Alternative revision: Added to my changed 'StringFromLogical': #define CACHE 16 if (!(*warn & CACHE)) {TrueCh = FalseCh = NULL; *warn |= CACHE;} No change to 'coerceToString' and 'coerceToSymbol'. -- On Friday, 11 April 2025 at 08:02:58 pm GMT+7, Suharto Anggono Suharto Anggono wr

Re: [Rd] table() and as.character() performance for logical values

2025-04-11 Thread Suharto Anggono Suharto Anggono via R-devel
Oh, with the abuse of 'warn' in my previous message, warning would be issued if the input 'v' of 'coerceToString' is a logical vector of length 1. Revision: Added to my changed 'StringFromLogical': if (*warn) {TrueCh = FalseCh = NULL; *warn = 0;} 'coerceToString': insert if (i == 0) warn = 1;

Re: [Rd] table() and as.character() performance for logical values

2025-04-11 Thread Suharto Anggono Suharto Anggono via R-devel
On second thought, I wonder if the caching in my changed 'StringFromLogical' in my previous message is safe. While 'ans' in the C function 'coerceToString' is protected, its element is also protected. If the object corresponding to 'ans' is then no longer protected, is it possible for the cache

Re: [Rd] table() and as.character() performance for logical values

2025-04-10 Thread Sebastian Meyer
Right, thanks! These are non-standard uses of factor(), edge cases I alluded to. We didn't see any problems with the patch in existing tests nor in CRAN/BIOC package checks. Note that 'levels' is documented as an optional vector of the unique values (as character strings) that ‘x’ might

Re: [Rd] table() and as.character() performance for logical values

2025-04-10 Thread Martin Maechler
> Suharto Anggono Suharto Anggono via R-devel > on Thu, 10 Apr 2025 07:53:04 + (UTC) writes: > Chain of calls of C functions in coerce.c for as.character() in R: > do_asatomic > ascommon > coerceVector > coerceToString > StringFromLogical (for each elemen

Re: [Rd] table() and as.character() performance for logical values

2025-04-10 Thread Suharto Anggono Suharto Anggono via R-devel
Chain of calls of C functions in coerce.c for as.character() in R: do_asatomic ascommon coerceVector coerceToString StringFromLogical (for each element) The definition of 'StringFromLogical' in coerce.c : attribute_hidden SEXP StringFromLogical(int x, int *warn) { int w; formatLogical(&x,

Re: [Rd] table() and as.character() performance for logical values

2025-04-08 Thread Suharto Anggono Suharto Anggono via R-devel
With the change to 'factor', factor(1L, levels = TRUE) doesn't give NA, different from factor(1, levels = TRUE) With the change to 'factor', factor(TRUE, levels = 1L) and factor(TRUE, levels = 1) don't give NA. With the change to 'factor', factor(2L, levels = sqrt(2)^2) gives NA, different from f

Re: [Rd] table() and as.character() performance for logical values

2025-03-24 Thread Sebastian Meyer
Am 21.03.25 um 15:42 schrieb Aidan Lakshman via R-devel: After investigating the source of table, I ended up on the reason being “as.character()”: This is specifically happening within the conversion of the input to type factor, which is where the as.character conversion happens. Yes, I als

Re: [Rd] table() and as.character() performance for logical values

2025-03-21 Thread Aidan Lakshman via R-devel
Some small points to add on this discussion: > After investigating the source of table, I ended up on the reason being > “as.character()”: This is specifically happening within the conversion of the input to type factor, which is where the as.character conversion happens. # Timing is all on