object-orientedsystems in RIldi Czeller : @czeildi
View Slide
- Data Scientist @Emarsys- 3 years R- started with C++, PythonMe:
- R user without CS background- understand core concepts- explore & debug more effectivelyYou:
summary(lm(y~x))...Coefficients:...Signif codes: 0 ‘***’Multiple R-squared:0.7262Min. : 1.01st Qu.: 25.8Median : 50.5Mean : 10049.53rd Qu.: 75.2Max. :1000000.0summary(c(1:99, 10^6))
date: 2018-10-27venue: Belgrade# participants: 100+attend -> learntalk at -> feedbackorganize -> prouddatabehavior +object =
S3
+36 1 333-3333
lm(y~x)summarysummary.lm CoefR^2
lm(y~x)summarysummary.lmdispatch methodclass+generic+
details
class / object type
type/class in RintegercharacterlistDatedata.framer_conferencebase typesS3 types
methodsummary.lmgeneric classas.factor
methodsummary.data.framegeneric classas.Date.numericclassgeneric
genericsummary UseMethod(“summary”)sum .Primitive(“sum”)
summary(lm(y~x))Coefficients: …Signif codes: 0 ‘***’Multiple R-squared:0.7262summary.lm(lm(y~x))dispatch
why sopowerful?
flexible &extensible
base R +different packageswork together
complex typescan inherit behaviorfrom simpler types
class is a vectorc(”r_conference”, “conference”, “event”)most specific à à à least specific
specialize• print(data.table())• print.data.table(data.table())Sepal.Length Sepal.Width1: 5.1 3.52: 4.9 3.03: 4.7 3.24: 4.6 3.15: 5.0 3.6---146: 6.7 3.0147: 6.3 2.5148: 6.5 3.0149: 6.2 3.4150: 5.9 3.0• print(data.frame())• print.data.frame(data.frame())Sepal.Length Sepal.Width1 5.1 3.52 4.9 3.03 4.7 3.24 4.6 3.15 5.0 3.66 5.4 3.97 4.6 3.48 5.0 3.49 4.4 2.910 4.9 3.1…
fallback• summary(data.table())• summary.data.table(data.table())• summary.data.frame(data.table())Sepal.LengthMin. :4.3001st Qu.:5.100Median :5.800Mean :5.8433rd Qu.:6.400Max. :7.900• summary(data.frame())• summary.data.frame(data.frame())Sepal.LengthMin. :4.3001st Qu.:5.100Median :5.800Mean :5.8433rd Qu.:6.400Max. :7.900
extendgift.conference gift.r_conference
learn more
explore• seq.Date• data.table:::print.data.table• lookup::lookup(“sum”) – Jim Hester• https://github.com/wch/r-source
explore• sloop – R package by Hadley Wickham• s3_class, ftype• s3_dispatch• s3_methods_class, s3_methods_generic
Advanced R by Hadley Wickhamhttps://www.ildiczeller.com/2018/04/02/investigating-difftime-behavior/
take-away
useunderstand(create)