Skip to content

type checking --- just a thought

3 messages · ivo welch, A.J. Rossini, Peter Dalgaard

#
hi:  would it be useful to build into R an optional mechanism that 
typechecks arguments?  for example,

    sum.across <- function (  inpmatrix : matrixtype( dim[1]>1, dim[2]>3 
) ) : vector { }
       # this would define a sum.across function that can take matrices 
or data sets, but not vectors,
       # and which indicates that it will return a vector.

    xsum <- sum.across( 1:10 );  # error

    repeat <- function( series : vector( dim>0 ),  times : scalar( 
value>0 ) ) : vector;

similarly, a common input error condition may be calling a function with 
a NULL vector, or with a vector with fewer than N observations.  many 
statistical functions have such hard-wired limits.  I know that "if" 
statements can do this, but this might make for a nice standardized 
language feature.  on the other hand, the effort and complexity may not 
be worth the extra functionality.

and one beg to the language maintainers for something that I hope is simple:

    in R 1.8.2, please add to the "source" function information where 
(file:linenumber) dies or ends.

regards,

/ivo
#
S4 methods take care of some of this checking (more specification
needed). 

best,
-tony

ivo welch <ivo.welch at yale.edu> writes:

  
    
#
ivo welch <ivo.welch at yale.edu> writes:
It's not simple because it is not a simple line-by-line evaluation.
The whole file is parsed and the resulting code then executed, by
which time the line information has been lost. If you can come up with
a well thought out scheme for retaining it, patches might be
considered. (There's not much chance of getting an R 1.8.2, though.)