On 4 January 2013 17:47, Bert Gunter <gunter.ber...@gene.com> wrote: > Inline. > > On Fri, Jan 4, 2013 at 7:44 AM, Suzen, Mehmet <msu...@gmail.com> wrote: >> >> I am always reserved about types and not sure how R auto casting works >> internally. >> In a large code using many different packages, I think being reserved >> about >> this would not hurt. >> >> Also, are there anyway to force R to be "strongly typed" similar to >> Occaml etc... > > > Yes (I think). Use S4. See. e.g. Chambers: Software for Data Analysis" > Programming in R >
Thank you Bert for point out S4. Here is one trivial example: > setClass("integerVector", representation(x="integer")) > iv<-new("integerVector") > iv@x <- c(1, 0, 1, 0, 2, 3) Error in checkSlotAssignment(object, name, value) : assignment of an object of class “numeric” is not valid for slot ‘x’ in an object of class “integerVector”; is(value, "integer") is not TRUE > iv@x <- as.integer(c(1, 0, 1, 0, 2, 3)) So this is pretty safe: > sum(iv@x == 0) [1] 2 ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.