Re: [Rd] CTRL-C during .Call causes R to quit to command line

2009-03-30 Thread Sklyar, Oleg (London)
If you use JNI or rJava, you should start the VM with -Xrs argument,
otherwise the descibed things happen as Java catches the Ctrl-C
interrupt

Dr Oleg Sklyar
Research Technologist
AHL / Man Investments Ltd
+44 (0)20 7144 3107
oskl...@maninvestments.com 

 -Original Message-
 From: r-devel-boun...@r-project.org 
 [mailto:r-devel-boun...@r-project.org] On Behalf Of Saptarshi Guha
 Sent: 30 March 2009 04:24
 To: r-devel@r-project.org
 Subject: [Rd] CTRL-C during .Call causes R to quit to command line
 
 Hello,
 During a .Call e.g
 while(TRUE){
 value -rhsqnextKVR(rdr)  ## has .Call in this function
 if(is.null(value)) break;
   }
 if I press CTRL-C, R exits straight to the command line.
 
 Q: How can I prevent this? I should point out that my library uses
 JNI, so I'm not sure if that is causing it.
 I'm using R-2.8 on Linux (RHEL 5)
 Thank you in advance
 Regards
 Saptarshi
 
 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel
 

**
Please consider the environment before printing this email or its attachments.
The contents of this email are for the named addressees ...{{dropped:19}}

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


[Rd] quantile and IQR do not check for numeric input (PR#13631)

2009-03-30 Thread sgiannerini
This report follows the post

http://tolstoy.newcastle.edu.au/R/e6/devel/09/03/0760.html

where it is shown that quantile() and IQR() do not work as documented.
In fact they do not check for numeric input even if the documentation says =
:

?quantile
x  numeric vectors whose sample quantiles are wanted. Missing
values are ignored.

?IQR

x   a numeric vector.

 quantile(factor(1:9))
  0%  25%  50%  75% 100%
   13579
Levels: 1 2 3 4 5 6 7 8 9

 IQR(factor(1:9))
[1] 4

 R.version
   _
platform   i386-pc-mingw32
arch   i386
os mingw32
system i386, mingw32
status alpha
major  2
minor  9.0
year   2009
month  03
day26
svn rev48224
language   R
version.string R version 2.9.0 alpha (2009-03-26 r48224)

--
__

Simone Giannerini
Dipartimento di Scienze Statistiche Paolo Fortunati
Universita' di Bologna
Via delle belle arti 41 - 40126 =A0Bologna, =A0ITALY
Tel: +39 051 2098262 =A0Fax: +39 051 232153
http://www2.stat.unibo.it/giannerini/

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


Re: [Rd] quantile and IQR do not check for numeric input (PR#13631)

2009-03-30 Thread Thomas Lumley

On Mon, 30 Mar 2009 sgianner...@gmail.com wrote:


This report follows the post

http://tolstoy.newcastle.edu.au/R/e6/devel/09/03/0760.html

where it is shown that quantile() and IQR() do not work as documented.


Nothing of the sort is shown! The thread argued that methods for these 
functions for ordered factors would be useful.


In fact they do not check for numeric input even if the documentation says =
:

?quantile
x  numeric vectors whose sample quantiles are wanted. Missing
values are ignored.

?IQR

x   a numeric vector.



The documentation says that you are not allowed to pass anything except a 
numeric vector to quantile() and IQR(). It doesn't, for example, say you can 
pass an arbitrary vector that will be checked to see if it is numeric. If you 
have code that passes a factor to IQR(), the bug is in that code.

On the other hand, as someone else has since reported, the 'missing values are 
ignored' statement in ?quantile is wrong (or at least incomplete).


-thomas

Thomas Lumley   Assoc. Professor, Biostatistics
tlum...@u.washington.eduUniversity of Washington, Seattle

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


Re: [Rd] quantile and IQR do not check for numeric input (PR#13631)

2009-03-30 Thread Duncan Murdoch

On 3/30/2009 7:50 AM, Thomas Lumley wrote:

On Mon, 30 Mar 2009 sgianner...@gmail.com wrote:


This report follows the post

http://tolstoy.newcastle.edu.au/R/e6/devel/09/03/0760.html

where it is shown that quantile() and IQR() do not work as documented.


Nothing of the sort is shown! The thread argued that methods for these 
functions for ordered factors would be useful.


In fact they do not check for numeric input even if the documentation says =
:

?quantile
x  numeric vectors whose sample quantiles are wanted. Missing
values are ignored.

?IQR

x   a numeric vector.



The documentation says that you are not allowed to pass anything except a 
numeric vector to quantile() and IQR(). It doesn't, for example, say you can 
pass an arbitrary vector that will be checked to see if it is numeric. If you 
have code that passes a factor to IQR(), the bug is in that code.

On the other hand, as someone else has since reported, the 'missing values are 
ignored' statement in ?quantile is wrong (or at least incomplete).


I think that statement was wrong, and I fixed it last night, but then 
didn't get it committed.  The commit will make it into 2.9 and R-devel 
today.


Duncan Murdoch

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


Re: [Rd] quantile and IQR do not check for numeric input (PR#13631)

2009-03-30 Thread Simone Giannerini
Dear Thomas,

On Mon, Mar 30, 2009 at 1:50 PM, Thomas Lumley tlum...@u.washington.edu wrote:
 On Mon, 30 Mar 2009 sgianner...@gmail.com wrote:

 This report follows the post

 http://tolstoy.newcastle.edu.au/R/e6/devel/09/03/0760.html

 where it is shown that quantile() and IQR() do not work as documented.

 Nothing of the sort is shown! The thread argued that methods for these
 functions for ordered factors would be useful.

in the original thread  I initiated the matters were two (at least in
my intention)

1. quantile() and IQR() do not check for numeric input whereas
median() has a check (for a factor input). This has nothing to deal
with ordered factors

2. the opportunity of having methods for ordered factors for
quantile() and the like.

If, for some reason, you think that it is ok to have such check for
median but not for quantile and IQR then take this as a wishlist. BTW
also var() and the like do not check for factor input while mean() has
the check.

 x - factor(letters[1:9])
 x
[1] a b c d e f g h i
Levels: a b c d e f g h i
 mean(x)
[1] NA
Warning message:
In mean.default(x) : argument is not numeric or logical: returning NA
 var(x)
[1] 7.5


Regards

Simone


 In fact they do not check for numeric input even if the documentation says
 =
 :

 ?quantile
 x      numeric vectors whose sample quantiles are wanted. Missing
 values are ignored.

 ?IQR

 x       a numeric vector.


 The documentation says that you are not allowed to pass anything except a
 numeric vector to quantile() and IQR(). It doesn't, for example, say you can
 pass an arbitrary vector that will be checked to see if it is numeric. If
 you have code that passes a factor to IQR(), the bug is in that code.

 On the other hand, as someone else has since reported, the 'missing values
 are ignored' statement in ?quantile is wrong (or at least incomplete).


    -thomas

 Thomas Lumley                   Assoc. Professor, Biostatistics
 tlum...@u.washington.edu        University of Washington, Seattle






-- 
__

Simone Giannerini
Dipartimento di Scienze Statistiche Paolo Fortunati
Universita' di Bologna
Via delle belle arti 41 - 40126  Bologna,  ITALY
Tel: +39 051 2098262  Fax: +39 051 232153
http://www2.stat.unibo.it/giannerini/

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


[Rd] duplicated fails to rise correct errors (PR#13632)

2009-03-30 Thread waku
Full_Name: Wacek Kusnierczyk
Version: 2.8.0 and 2.10.0 r48242
OS: Ubuntu 8.04 Linux 32 bit
Submission from: (NULL) (129.241.110.161)


In the following code:

   duplicated(data.frame(), incomparables=NA)
   # Error in if (!is.logical(incomparables) || incomparables)
.NotYetUsed(incomparables != FALSE) : 
   # missing value where TRUE/FALSE needed

the raised error is clearly not the one intended to be raised.

?duplicated says:


incomparables: a vector of values that cannot be compared. 'FALSE' is a
  special value, meaning that all values can be compared, and
  may be the only value accepted for methods other than the
  default.  It will be coerced internally to the same type as
  'x'.

(...)

 Values in 'incomparables' will never be marked as duplicated. This
 is intended to be used for a fairly small set of values and will
 not be efficient for a very large set.


However, in duplicated.data.frame (which is called when duplicated is applied to
a data frame, as above) the parameter 'incomparables' is defunct.  The
documentation fails to explain this, and it might be a good idea to improve it.

In the code for duplicated.data.frame there is an attempt to intercept any use
of the parameter 'incomparables' with a value other than FALSE and to raise an
appropriate error, but this attempt fails with, e.g., incomparables=NA.

Incidentally, the attempt to intercept incomparables != FALSE fails completely
(i.e., the call to duplicated succeeds) with certain inputs:

   duplicated(data.frame(logical=c(TRUE, TRUE)), incomparables=c(FALSE, TRUE))
   # [1] FALSE TRUE

while

   duplicated(c(TRUE, TRUE), incomparables=c(FALSE, TRUE))
   # [1] FALSE FALSE


Regards,
vQ

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


Re: [Rd] duplicated fails to rise correct errors (PR#13632)

2009-03-30 Thread Wacek Kusnierczyk
the bug seems to have a trivial solution;  as far as i can see, it suffices to 
replace

if (!is.logical(incomparables) || incomparables)

with

if(!identical(incomparables, FALSE))

in all its occurrences in src/library/base/R/duplicated.R

attached is a patch created, successfully tested and installed on Ubuntu 8.04 
Linux 32 bit as follows:

svn co https://svn.r-project.org/R/trunk trunk
cd trunk
# edit src/library/base/R/duplicated.R
svn diff  duplicated.R.diff

svn revert -R src
patch -p0  duplicated.R.diff
tools/rsync-recommended
./configure
make
make check

and now

duplicated(data.frame(), incomparables=NA)
# error: argument 'incomparables != FALSE' is not used (yet)

regards,
vQ



waclaw.marcin.kusnierc...@idi.ntnu.no wrote:
 Full_Name: Wacek Kusnierczyk
 Version: 2.8.0 and 2.10.0 r48242
 OS: Ubuntu 8.04 Linux 32 bit
 Submission from: (NULL) (129.241.110.161)


 In the following code:

duplicated(data.frame(), incomparables=NA)
# Error in if (!is.logical(incomparables) || incomparables)
 .NotYetUsed(incomparables != FALSE) : 
# missing value where TRUE/FALSE needed

 the raised error is clearly not the one intended to be raised.

 ?duplicated says:

 
 incomparables: a vector of values that cannot be compared. 'FALSE' is a
   special value, meaning that all values can be compared, and
   may be the only value accepted for methods other than the
   default.  It will be coerced internally to the same type as
   'x'.

 (...)

  Values in 'incomparables' will never be marked as duplicated. This
  is intended to be used for a fairly small set of values and will
  not be efficient for a very large set.
 

 However, in duplicated.data.frame (which is called when duplicated is applied 
 to
 a data frame, as above) the parameter 'incomparables' is defunct.  The
 documentation fails to explain this, and it might be a good idea to improve 
 it.

 In the code for duplicated.data.frame there is an attempt to intercept any use
 of the parameter 'incomparables' with a value other than FALSE and to raise an
 appropriate error, but this attempt fails with, e.g., incomparables=NA.

 Incidentally, the attempt to intercept incomparables != FALSE fails completely
 (i.e., the call to duplicated succeeds) with certain inputs:

duplicated(data.frame(logical=c(TRUE, TRUE)), incomparables=c(FALSE, TRUE))
# [1] FALSE TRUE

 while

duplicated(c(TRUE, TRUE), incomparables=c(FALSE, TRUE))
# [1] FALSE FALSE


 Regards,
 vQ

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


-- 
---
Wacek Kusnierczyk, MD PhD

Email: w...@idi.ntnu.no
Phone: +47 73591875, +47 72574609

Department of Computer and Information Science (IDI)
Faculty of Information Technology, Mathematics and Electrical Engineering (IME)
Norwegian University of Science and Technology (NTNU)
Sem Saelands vei 7, 7491 Trondheim, Norway
Room itv303

Bioinformatics  Gene Regulation Group
Department of Cancer Research and Molecular Medicine (IKM)
Faculty of Medicine (DMF)
Norwegian University of Science and Technology (NTNU)
Laboratory Center, Erling Skjalgsons gt. 1, 7030 Trondheim, Norway
Room 231.05.060

---

Index: src/library/base/R/duplicated.R
===
--- src/library/base/R/duplicated.R	(revision 48242)
+++ src/library/base/R/duplicated.R	(working copy)
@@ -25,7 +25,7 @@
 
 duplicated.data.frame - function(x, incomparables = FALSE, fromLast = FALSE, ...)
 {
-if(!is.logical(incomparables) || incomparables)
+if (!identical(incomparables, FALSE))
 	.NotYetUsed(incomparables != FALSE)
 duplicated(do.call(paste, c(x, sep=\r)), fromLast = fromLast)
 }
@@ -33,7 +33,7 @@
 duplicated.matrix - duplicated.array -
 function(x, incomparables = FALSE , MARGIN = 1L, fromLast = FALSE, ...)
 {
-if(!is.logical(incomparables) || incomparables)
+if (!identical(incomparables, FALSE))
 	.NotYetUsed(incomparables != FALSE)
 ndim - length(dim(x))
 if (length(MARGIN)  ndim || any(MARGIN  ndim))
@@ -67,7 +67,7 @@
 
 unique.data.frame - function(x, incomparables = FALSE, fromLast = FALSE, ...)
 {
-if(!is.logical(incomparables) || incomparables)
+if (!identical(incomparables, FALSE))
 	.NotYetUsed(incomparables != FALSE)
 x[!duplicated(x, fromLast = fromLast),  , drop = FALSE]
 }
@@ -75,7 +75,7 @@
 unique.matrix - unique.array -
 function(x, incomparables = FALSE , MARGIN = 1, fromLast = FALSE, ...)
 {
-if(!is.logical(incomparables) || incomparables)
+if (!identical(incomparables, FALSE))
 	.NotYetUsed(incomparables != FALSE)
 ndim - length(dim(x))
 if (length(MARGIN)  1L || any(MARGIN  ndim))

Re: [Rd] if does not covert raw to logical (PR#13630)

2009-03-30 Thread maechler
Thank you, Wacek,
for

 Wacek Kusnierczyk w...@idi.ntnu.no
 on Sun, 29 Mar 2009 22:40:11 +0200 (CEST) writes:

 Full_Name: Wacek Kusnierczyk
 Version: 2.8.0 and 2.10.0 r48242
 OS: Ubuntu 8.04 Linux 32 bit
 Submission from: (NULL) (80.202.30.36)


 The following raises an error:

 if (as.raw(1)) 1
 # error: unimplemented type 'raw' in 'asLogical'

 However, ?'if' says:

  
 Arguments:

 cond: A length-one logical vector that is not 'NA'. Conditions of
 length greater than one are accepted with a warning, but only
 the first element is used.  Other types are coerced to
 logical if possible, ignoring any class. 
 

 and the help page does not mention raw type arguments to 'if' at all. 

 The error above is in clear contradiction to the documentation.  This 
might be a
 flaw in the documentation, but the following succeeds:

 ifelse(raw(1), 1, 0)
 # 1

 which suggests that the error above is a bug (i.e., the implementation 
fails to
 convert raw to logical).

 The same problem involves 'while':

 while(as.raw(1)) break
 # error: unimplemented type 'raw' in 'asLogical'

indeed, it was pretty straightforward hard to implement the missing case in
asLogical(.) and I will commit my patch to the sources tomorrow
{being busy otherwise for the rest of today}.

Note that  the  raw data type has been a newish addition to R a
while ago though,  and if you find further cases where
such raw objects do not work as documented,
we'd gladly accept further such reports.

Regards,
Martin Maechler, ETH Zurich

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


Re: [Rd] Gamma funtion(s) bug

2009-03-30 Thread Ted Harding
On 30-Mar-09 18:40:03, Kjetil Halvorsen wrote:
 With R 2.8.1 on ubuntu I get:
 gamma(-1)
 [1] NaN
 Warning message:
 In gamma(-1) : NaNs produced
 lgamma(-1)
 [1] Inf
 Warning message:
 value out of range in 'lgamma'
 
 Is'nt the first one right, and the second one (lgamma)
 should also be NaN?
 Kjetil

That is surely correct! Since lim[x-(-1)+] gamma(x) = +Inf,
while lim[x-(-1)-] gamma(x) = -Inf, at gamma(-1) one cannot
choose between +Inf and -Inf, so surely is is NaN.

Ted.


E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
Fax-to-email: +44 (0)870 094 0861
Date: 30-Mar-09   Time: 19:55:33
-- XFMail --

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


Re: [Rd] if does not covert raw to logical (PR#13630)

2009-03-30 Thread Waclaw . Marcin . Kusnierczyk
Martin Maechler wrote:
 Thank you, Wacek,
   
happy to serve.
(...)
 indeed, it was pretty straightforward hard to implement the missing case in
 asLogical(.) and I will commit my patch to the sources tomorrow
 {being busy otherwise for the rest of today}.
   

thanks!

 Note that  the  raw data type has been a newish addition to R a
 while ago though,  and if you find further cases where
 such raw objects do not work as documented,
 we'd gladly accept further such reports.
   

yes, i'll keep sniffing.

best,
vQ

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


Re: [Rd] Gamma funtion(s) bug

2009-03-30 Thread Duncan Murdoch

On 3/30/2009 2:55 PM, (Ted Harding) wrote:

On 30-Mar-09 18:40:03, Kjetil Halvorsen wrote:

With R 2.8.1 on ubuntu I get:

gamma(-1)

[1] NaN
Warning message:
In gamma(-1) : NaNs produced

lgamma(-1)

[1] Inf
Warning message:
value out of range in 'lgamma'

Is'nt the first one right, and the second one (lgamma)
should also be NaN?
Kjetil


That is surely correct! Since lim[x-(-1)+] gamma(x) = +Inf,
while lim[x-(-1)-] gamma(x) = -Inf, at gamma(-1) one cannot
choose between +Inf and -Inf, so surely is is NaN.


But lgamma(x) is log(abs(gamma(x))), so it looks okay to me.

Duncan Murdoch

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


Re: [Rd] Gamma funtion(s) bug

2009-03-30 Thread Ted Harding
On 30-Mar-09 20:37:51, Duncan Murdoch wrote:
 On 3/30/2009 2:55 PM, (Ted Harding) wrote:
 On 30-Mar-09 18:40:03, Kjetil Halvorsen wrote:
 With R 2.8.1 on ubuntu I get:
 gamma(-1)
 [1] NaN
 Warning message:
 In gamma(-1) : NaNs produced
 lgamma(-1)
 [1] Inf
 Warning message:
 value out of range in 'lgamma'
 
 Is'nt the first one right, and the second one (lgamma)
 should also be NaN?
 Kjetil
 
 That is surely correct! Since lim[x-(-1)+] gamma(x) = +Inf,
 while lim[x-(-1)-] gamma(x) = -Inf, at gamma(-1) one cannot
 choose between +Inf and -Inf, so surely is is NaN.
 
 But lgamma(x) is log(abs(gamma(x))), so it looks okay to me.
 
 Duncan Murdoch

Oops, yes! That's what comes of talking off the top of my head
(I don't think I've ever had occasion to evaluate lgamma(x)
for negative x, so never consciously checked in ?lgamma).

Thanks, Duncan!
Ted.


E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
Fax-to-email: +44 (0)870 094 0861
Date: 30-Mar-09   Time: 22:28:52
-- XFMail --

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


[Rd] Possible bug in summary.survfit - 'scale' argument ignored?

2009-03-30 Thread Marc Schwartz

Hi all,

Using:

  R version 2.8.1 Patched (2009-03-07 r48068)

on OSX (10.5.6) with survival version:

  Version:2.35-3
  Date:   2009-02-10


I get the following using the first example in ?summary.survfit:

 summary( survfit( Surv(futime, fustat)~1, data=ovarian))
Call: survfit(formula = Surv(futime, fustat) ~ 1, data = ovarian)

 time n.risk n.event survival std.err lower 95% CI upper 95% CI
   59 26   10.962  0.03770.8901.000
  115 25   10.923  0.05230.8261.000
  156 24   10.885  0.06270.7701.000
  268 23   10.846  0.07080.7180.997
  329 22   10.808  0.07730.6700.974
  353 21   10.769  0.08260.6230.949
  365 20   10.731  0.08700.5790.923
  431 17   10.688  0.09190.5290.894
  464 15   10.642  0.09650.4780.862
  475 14   10.596  0.09990.4290.828
  563 12   10.546  0.10320.3770.791
  638 11   10.497  0.10510.3280.752


 summary( survfit( Surv(futime, fustat)~1, data=ovarian), scale =  
365.25)

Call: survfit(formula = Surv(futime, fustat) ~ 1, data = ovarian)

 time n.risk n.event survival std.err lower 95% CI upper 95% CI
   59 26   10.962  0.03770.8901.000
  115 25   10.923  0.05230.8261.000
  156 24   10.885  0.06270.7701.000
  268 23   10.846  0.07080.7180.997
  329 22   10.808  0.07730.6700.974
  353 21   10.769  0.08260.6230.949
  365 20   10.731  0.08700.5790.923
  431 17   10.688  0.09190.5290.894
  464 15   10.642  0.09650.4780.862
  475 14   10.596  0.09990.4290.828
  563 12   10.546  0.10320.3770.791
  638 11   10.497  0.10510.3280.752

Of course the time periods in the second output should be scaled to  
years, that is (time / 365.25).


I noted this today running some Sweave code, but not sure when the  
actual change in behavior occurred.  I can replicate the same behavior  
on a Windows machine here as well, so this is not OSX specific.


Regards,

Marc Schwartz

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


[Rd] external equiv to R_serialize()?

2009-03-30 Thread Joe Conway
I'm trying to efficiently allow conversion of R objects to PostgreSQL 
bytea (raw binary) datatype within PL/R for persistent storage in 
Postgres tables. I have found R_serialize() which looks like what I 
need, -- e.g. R_serialize(object, NULL, FALSE, NULL) -- except that it 
is marked attribute_hidden. Is there some other externally available 
interface that I can use?


Thanks,

Joe

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