Dear all, while looking for some inspiration of how to organise some code, I studied the code of random.c and noticed that for distributions with 2 or 3 parameters the user is not warned if NAs are created while such a warning is issued for distributions with 1 parameter. E.g:
R version 2.7.0 Under development (unstable) (2008-02-29 r44639) [...] > rexp(2, rate=Inf) [1] NaN NaN Warning message: In rexp(2, rate = Inf) : NAs produced > rnorm(2, mean=Inf) [1] NaN NaN Surprisingly, the code for issuing warnings for distributions with 2 or 3 parameters is essentially there, but does not seem to be used. The attached patch rectifies this. With the patch the above command produce the following output: > rexp(2, rate=Inf) [1] NaN NaN Warning message: In rexp(2, rate = Inf) : NAs produced > rnorm(2, mean=Inf) [1] NaN NaN Warning message: In rnorm(2, mean = Inf) : NAs produced Please ignore the patch if the code that was designed to produce the warning had been removed on purpose. BTW, there are other places in the code were NAs can be created but no warning is issued. E.g: > rexp(2, rate=numeric()) [1] NA NA > rnorm(2, mean=numeric()) [1] NA NA I wonder whether a warning should be issued in this case too. Best wishes, Berwin
Index: src/main/random.c =================================================================== --- src/main/random.c (revision 44639) +++ src/main/random.c (working copy) @@ -123,7 +123,7 @@ #define RAND2(num,name) \ case num: \ - random2(name, REAL(a), na, REAL(b), nb, REAL(x), n); \ + naflag = random2(name, REAL(a), na, REAL(b), nb, REAL(x), n); \ break /* "do_random2" - random sampling from 2 parameter families. */ @@ -207,7 +207,7 @@ #define RAND3(num,name) \ case num: \ - random3(name, REAL(a), na, REAL(b), nb, REAL(c), nc, REAL(x), n); \ + naflag = random3(name, REAL(a), na, REAL(b), nb, REAL(c), nc, REAL(x), n); \ break
______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel