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 } 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] Martin Maechler <maechler@stat.math.ethz.ch> http://stat.ethz.ch/~maechler/ Seminar fuer Statistik, ETH-Zentrum LEO D10 Leonhardstr. 27 ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND phone: x-41-1-632-3408 fax: ...-1228 <>< -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 }The idiom in "another place" is storage.mode(x) <- "integer" storage.mode(x) <- "double" &c my preference would again be for convergence of the two dialects. (Of course when S4 takes over that other place, this sort of consideration becomes much less relevant.) Bill Venables.>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] > >Martin Maechler <maechler@stat.math.ethz.ch> http://stat.ethz.ch/~maechler/ >Seminar fuer Statistik, ETH-Zentrum LEO D10 Leonhardstr. 27 >ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND >phone: x-41-1-632-3408 fax: ...-1228 <>< >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.->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 >_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._> >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> From: Martin Maechler <maechler@stat.math.ethz.ch> > Date: 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 beworth 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.What the help page says is The two assignment versions are currently identical. ^^^^^^^^^ and I am not sure we want that to remain so, nor should we assume so. I think R's use of all of mode and typeof and storage.mode is confusing, especially as the first and third are diluted versions of the second. (Without looking, how many of you know the exact differences?) asmode.integer(x) and (storage.mode(x) <- "integer"; x) seem to be to just be (in R) cumbersome ways to do structure(as.integer(x), attributes(x))> 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)Sooner than you might think. What was announced as the last ever release of a version of S-PLUS based on Svr3 was released a few days ago. The future there is S-PLUS 6.x and Svr4 only. -- Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._