[R] Sum of logical vector

Tuszynski, Jaroslaw W. JAROSLAW.W.TUSZYNSKI at saic.com
Mon Oct 31 20:00:51 CET 2005


Hi,

Recently I was told by users of some of the function I wrote that they
experience crashes in places where logical vector was passed to sum
function. However on my computer those functions work just fine. After
closer look at documentation of function 'sum', I realized that it is
defined only for complex and numeric vectors, so I guess I was using
"undocumented feature". 

What I am trying to understand is why it works on some systems (my - Win XP,
from R-1.9.? to R-2.2.0) and does not work on other (unknown platform,
R-2.2.0):
- Is it that they have more methods of function "sum" defined and some other
function (maybe some package has "logical.sum" defined) is being used?
- Different operating systems will have different behavior for supporting
"undocumented features"?

Is there any way to automatically test your code for presence of unsupported
functions it uses?
Should function 'sum' produced warning/error, or convert logical to integer?

An Example code:

 repeats = function(x) return (sum(duplicated(x)) ) # how many numbers
repeat themselves in vector x?
 repeats( c(1:10, 3:14) )

 Jarek 
====================================================\==== 
 Jarek Tuszynski, PhD.                           o / \ 
 Science Applications International Corporation  <\__,|  
 (703) 676-4192                                   ">  \ 
 Jaroslaw.W.Tuszynski at saic.com                     `   \




More information about the R-help mailing list