[Rd] Small typo in Writing R Extensions

2023-02-08 Thread Davis Vaughan via R-devel
Hi all, Writing R Extensions describes `R_NewEnv()` as: ``` At times it may also be useful to create a new environment frame in C code. R_NewEnv is a C version of the R function new.env: SEXP R_NewEnv(SEXP enclos, int hash, ins size) ``` There is a typo here where `ins size` should be `int size

[Rd] On optimizing `R_NewEnv()`

2023-02-08 Thread Davis Vaughan via R-devel
Hi all, I really like the addition of `R_NewEnv()` back in 4.1.0 https://github.com/wch/r-source/blob/625ab8d45f86f65561e53627e1f0c220bdc5f752/src/main/envir.c#L3619-L3630 I have a use case where I'm likely to call this function a large number of times to generate many small hashed environments,

[Rd] An alternative algorithm for `which()`

2023-04-05 Thread Davis Vaughan via R-devel
Hi all, I've sent in a bugzilla patch for an alternative C algorithm for `which()` which uses less memory and is often faster in many real life scenarios. I've documented it in full on the bugzilla page, with many examples: https://bugs.r-project.org/show_bug.cgi?id=18495 The short version is tha

[Rd] Possible inconsistency between `as.complex(NA_real_)` and the docs

2023-04-14 Thread Davis Vaughan via R-devel
Hi all, Surprisingly (at least to me), `as.complex(NA_real_)` results in `complex(real = NA_real_, imaginary = 0)` rather than `NA_complex_`. It seems to me that this goes against the docs of `as.complex()`, which say this in the Details section: "Up to R versions 3.2.x, all forms of NA and NaN

[Rd] range() for Date and POSIXct could respect `finite = TRUE`

2023-04-28 Thread Davis Vaughan via R-devel
Hi all, I noticed that `range.default()` has a nice `finite = TRUE` argument, but it doesn't actually apply to Date or POSIXct due to how `is.numeric()` works. ``` x <- .Date(c(0, Inf, 1, 2, Inf)) x #> [1] "1970-01-01" "Inf""1970-01-02" "1970-01-03" "Inf" # Darn! range(x, finite = TRUE)

Re: [Rd] range() for Date and POSIXct could respect `finite = TRUE`

2023-05-01 Thread Davis Vaughan via R-devel
`finite`. Because `is.numeric.Date()` is defined, that always returns `FALSE` for Dates (and POSIXt). Because of that, it may still be easier to just write a specific `range.Date()` method, but I'm not sure. -Davis On Sat, Apr 29, 2023 at 4:47 PM Martin Maechler wrote: > > >>>&g

Re: [Rd] range() for Date and POSIXct could respect `finite = TRUE`

2023-05-09 Thread Davis Vaughan via R-devel
function(..., na.rm = FALSE, finite = FALSE) > .rangeNum(..., na.rm=na.rm, finite=finite, isNumeric = is.numeric) > > range.POSIXct <- range.Date <- function(..., na.rm = FALSE, finite = FALSE) > .rangeNum(..., na.rm=na.rm, finite=finite, isNumeric = function

[Rd] Should `expand.grid()` consistently drop `NULL` inputs?

2023-10-02 Thread Davis Vaughan via R-devel
Hi all, I noticed that `expand.grid()` has somewhat inconsistent behavior with dropping `NULL` inputs. In particular, if there is a leading `NULL`, then it ends up as a column in the resulting data frame, which seems pretty undesirable. Also, notice in the last example that `Var3` is used as the c

[Rd] `as.data.frame.matrix()` can produce a data frame without a `names` attribute

2024-03-21 Thread Davis Vaughan via R-devel
Hi all, I recently learned that it is possible for `as.data.frame.matrix()` to produce a data frame with 0 columns that is also entirely missing a `names` attribute, and I think this is a bug: ``` # No `names`, weird! attributes(as.data.frame(matrix(nrow = 0, ncol = 0))) #> $class #> [1] "data.fr