[Rd] Unneeded if statements in RealFromComplex C code
Hi, I just stumbled across these 2 lines in RealFromComplex (lines 208 & 209 in src/main/coerce.c): double attribute_hidden RealFromComplex(Rcomplex x, int *warn) { if (ISNAN(x.r) || ISNAN(x.i)) return NA_REAL; if (ISNAN(x.r)) return x.r; <- line 208 if (ISNAN(x.i)) return NA_REAL; <- line 209 if (x.i != 0) *warn |= WARN_IMAG; return x.r; } They were added in 2015 (revision 69410). They don't serve any purpose and might slow things down a little (unless compiler optimization is able to ignore them). In any case they should probably be removed. Cheers, H. -- Hervé Pagès Bioconductor Core Team hpages.on.git...@gmail.com __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Should Position() use match.fun()?
> Kurt Hornik writes: > Steve Martin writes: >> Hello, >> All of the funprog functions except Position() use match.fun() early >> in the body of the function. (Filter() seems to rely on lapply() for >> this, but the effect is the same.) > Right. >> In most cases this isn't a problem, but I can't see why Position() >> shouldn't look something like >> Position2 <- function(f, x, right = FALSE, nomatch = NA_integer_) { >> f <- match.fun(f) # the only difference from Position() >> ind <- if (right) rev(seq_along(x)) else seq_along(x) >> for (i in ind) { >> if (f(x[[i]])) return(i) >> } >> nomatch >> } >> This would make it consistent with the other funprog functions, and >> would mean that Find() and Position() give the same result when >> expected > Indeed. I'll look into adding the match.fun ... Changed now with c80873. Best -k > Best > -k >>> equals3 <- function(x) x == 3 >>> Position("equals3", 1:5) >> Error in f(x[[i]]) : could not find function "f" >>> Position2("equals3", 1:5) >> [1] 3 >>> Find("equals3", 1:5) >> [1] 3 >> Thanks, >> Steve >> __ >> R-devel@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-devel > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Should Position() use match.fun()?
> Steve Martin writes: > Hello, > All of the funprog functions except Position() use match.fun() early > in the body of the function. (Filter() seems to rely on lapply() for > this, but the effect is the same.) Right. > In most cases this isn't a problem, but I can't see why Position() > shouldn't look something like > Position2 <- function(f, x, right = FALSE, nomatch = NA_integer_) { > f <- match.fun(f) # the only difference from Position() > ind <- if (right) rev(seq_along(x)) else seq_along(x) > for (i in ind) { > if (f(x[[i]])) return(i) > } > nomatch > } > This would make it consistent with the other funprog functions, and > would mean that Find() and Position() give the same result when > expected Indeed. I'll look into adding the match.fun ... Best -k >> equals3 <- function(x) x == 3 >> Position("equals3", 1:5) > Error in f(x[[i]]) : could not find function "f" >> Position2("equals3", 1:5) > [1] 3 >> Find("equals3", 1:5) > [1] 3 > Thanks, > Steve > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel