[Rd] Incorrect comment about ISNA(x) in Arith.h (PR#13826)

2009-07-14 Thread rocket
R-2.9.0/include/R_ext/Arith.h has:

int R_IsNA(double); /* True for R's NA only */
int R_IsNaN(double);/* True for special NaN, *not* for NA */
int R_finite(double);   /* True if none of NA, NaN, +/-Inf */

#define ISNA(x)R_IsNA(x)
/* True for *both* NA and NaN.

The first and last lines are contradictory - if R_IsNA is true only
for NA, not NaN, then ISNA should be the same.

Venables & Ripley S Programming p 137 indicates that
"ISNA does not detect NaN s"

Here's a little .c file and R transcript that shows that V&R are correct,
   ISNA(x) is not True for NaN
So the last comment should read
/* True for NA, not NaN



#include "R.h"
void mysum(double *x)
{
  double sum = 0.0;
  sum = x[0] + x[1] + x[2];
  if (ISNA(sum))
PROBLEM "sum is NA" WARNING(NULL_ENTRY);
  if (ISNAN(sum))
PROBLEM "sum is NAN" WARNING(NULL_ENTRY);
  if (!(R_FINITE(sum)))
PROBLEM "sum is not finite" WARNING(NULL_ENTRY);
  return;
}


> dyn.load("~/R/work/bug.so")
> .C("mysum", c(NaN, 0.0, 0.0), NAOK = TRUE, DUP = FALSE)
[[1]]
[1] NaN   0   0

Warning messages:
1: sum is NAN 
2: sum is not finite 



--please do not edit the information below--

Version:
 platform = x86_64-unknown-linux-gnu
 arch = x86_64
 os = linux-gnu
 system = x86_64, linux-gnu
 status = 
 major = 2
 minor = 9.0
 year = 2009
 month = 04
 day = 17
 svn rev = 48333
 language = R
 version.string = R version 2.9.0 (2009-04-17)

Locale:
LC_CTYPE=en_US;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=en_US;LC_PAPER=en_US;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US;LC_IDENTIFICATION=C

Search Path:
 .GlobalEnv, package:Rfixes, package:Rcode, package:aggregate, 
package:splus2Rgoogle, package:stats, package:graphics, package:grDevices, 
package:utils, package:datasets, package:methods, Autoloads, package:base

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] help (using ?) does not handle trailing whitespace (PR#11537)

2008-05-30 Thread rocket
> ?agrep 
> 

Results in:

No documentation for 'agrep ' in specified packages and libraries:
you could try 'help.search("agrep ")'

There is white space after agrep, that ? doesn't ignore.


--please do not edit the information below--

Version:
 platform = i486-pc-linux-gnu
 arch = i486
 os = linux-gnu
 system = i486, linux-gnu
 status = 
 major = 2
 minor = 7.0
 year = 2008
 month = 04
 day = 22
 svn rev = 45424
 language = R
 version.string = R version 2.7.0 (2008-04-22)

Locale:
LC_CTYPE=en_US;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=en_US;LC_PAPER=en_US;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US;LC_IDENTIFICATION=C

Search Path:
 .GlobalEnv, package:stats, package:graphics, package:grDevices, package:utils, 
package:datasets, package:showStructure, package:Rcode, package:splus2R, 
package:methods, Autoloads, package:base

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] scoping problem when calling lm(precomputed formula, weights) from function (PR#11540)

2008-05-30 Thread rocket
I've run into a scoping problem in R.
I'm calling a function that
   * creates a formula
   * calculates a weight vector
   * calls lm with that formula and weights
This fails.

Here's a simplified reproduce example:
# f works, g doesn't, h is a workaround
rm(w)
data <- data.frame(y=runif(20), x=runif(20), z=runif(20))
f <- function(k){
  w <- data$z^k
  coef(lm(y~x, data = data, weights = w))
}
g <- function(k){
  w <- data$z^k
  Formula <- parse(text="y~x")[[1]]
  coef(lm(Formula, data = data, weights = w))
}
h <- function(k){
  w <- data$z^k
  Formula <- parse(text="y~x")[[1]]
  # Following line fails due to scoping bug.  Use workaround.
  # coef(lm(Formula, data = data, weights = w))
  Call <- paste("coef(lm(", deparse(Formula), ", data=data, weights=w))")
  eval(parse(text=Call)[[1]])
}


> f(2)
(Intercept)   x 
  0.7452512  -0.3413998 
> g(2)
Error in eval(expr, envir, enclos) : object "w" not found
> traceback()
9: eval(expr, envir, enclos)
8: eval(extras, data, env)
7: model.frame.default(formula = Formula, data = data, weights = w, 
   drop.unused.levels = TRUE)
6: model.frame(formula = Formula, data = data, weights = w, drop.unused.levels 
= TRUE)
5: eval(expr, envir, enclos)
4: eval(mf, parent.frame())
3: lm(Formula, data = data, weights = w)
2: coef(lm(Formula, data = data, weights = w))
1: g(2)
> h(2)
(Intercept)   x 
  0.7452512  -0.3413998 



--please do not edit the information below--

Version:
 platform = i486-pc-linux-gnu
 arch = i486
 os = linux-gnu
 system = i486, linux-gnu
 status = 
 major = 2
 minor = 7.0
 year = 2008
 month = 04
 day = 22
 svn rev = 45424
 language = R
 version.string = R version 2.7.0 (2008-04-22)

Locale:
LC_CTYPE=en_US;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=en_US;LC_PAPER=en_US;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US;LC_IDENTIFICATION=C

Search Path:
 .GlobalEnv, package:stats, package:graphics, package:grDevices, package:utils, 
package:datasets, package:showStructure, package:Rcode, package:splus2R, 
package:methods, Autoloads, package:base

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel