[Rd] asmode.integer() -- RFC

Martin Maechler Martin Maechler <maechler@stat.math.ethz.ch>
Thu, 7 Sep 2000 15:12:14 +0200 (CEST)


>>>>> "Bill" == Bill Venables <Bill.Venables@cmis.csiro.au> writes:

    Bill> At 10:17 07/09/00 +0200, Martin Maechler wrote:
    >> Many of us known that sometimes, e.g. in calls to .C(..), you want to
    >> basically say
    >> 
    >> x <- as.integer(x)
    >> 
    >> but you can't do that because as.vector() 
    >> and it's descendants such as as.integer, as.double, as.character
    >> drop all attributes.
    >> 
    >> Several months ago, someone proposed to use a new function
    >> As.integer() instead.  
    >> Since I just now again "stumbled" on it, I wondered if it might be worth to
    >> define 
    >> 
    >> asmode.integer   <- function(x) { mode(x) <- "integer"   ; x }
    >> asmode.double    <- function(x) { mode(x) <- "double"    ; x }
    >> asmode.character <- function(x) { mode(x) <- "character" ; x }

    Bill> The idiom in "another place" is

    Bill>  storage.mode(x) <- "integer"
    Bill>  storage.mode(x) <- "double"  &c

I had this initially, but

    Bill> my preference would again be for convergence of the two dialects.
well, in R, "mode<-" and "storage.mode<-" are 100% equivalent.
in Splus 5.1, for the above case, they behave equivalently as well.
Hence, saving the extra  "storage." seemed feasible to me, and since I'm
occasionally fond of `minimal art' ......

I agree that "storage.mode" is more expressive...

    Bill> (Of course when S4 takes over that other place, this sort of
    Bill> consideration becomes much less relevant.)

(true, unfortunately)

    >> in order to encourage more shorter & more readable code...
    >> or would you hate to see yet more functions doing `almost the same' as
    >> others do?
    >> 
    >> [RFC = Request for comments]
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._