bookclub-advr

DSLC Advanced R Book Club
git clone https://git.eamoncaddigan.net/bookclub-advr.git
Log | Files | Refs | README | LICENSE

09.qmd (2354B)


      1 ---
      2 title: Cohort 9
      3 ---
      4 
      5 {{< video https://www.youtube.com/embed/4_hYWHOMM3k >}}
      6 
      7 <details>
      8 
      9 <summary>Meeting chat log</summary>
     10 ```
     11 00:06:56	Jeffrey Stevens:	Which book?
     12 00:07:03	Olivier Leroy:	SICP
     13 00:07:21	Olivier Leroy:	https://en.wikipedia.org/wiki/Structure_and_Interpretation_of_Computer_Programs
     14 00:10:27	Olivier Leroy:	Start
     15 00:14:35	Olivier Leroy:	More if you came from python
     16 00:24:13	Derek Sollberger:	possible example: US high school is grades 9:12, but a factor variable wants to also define grades 1:8 as well
     17 00:26:21	Diana Garcia Cortes:	x <- factor(10:20)
     18 > unclass(x)
     19  [1]  1  2  3  4  5  6  7  8  9 10 11
     20 attr(,"levels")
     21  [1] "10" "11" "12" "13" "14" "15" "16" "17" "18" "19" "20"
     22 00:26:52	Jo Hardin:	what do you get with max(unclass(x))
     23 00:27:25	Olivier Leroy:	r$> max(unclass(x))
     24 [1] 11
     25 00:28:49	Olivier Leroy:	r$> unclass(10:12)
     26 [1] 10 11 12
     27 00:31:00	Jeffrey Stevens:	"The constructor is a developer function: it will be called in many places, by an experienced user. That means it’s OK to trade a little safety in return for performance, and you should avoid potentially time-consuming checks in the constructor."
     28 00:33:53	Derek Sollberger:	# Simpsons reference
     29 > as.roman(5) + as.roman(2)
     30 [1] VII
     31 00:48:27	Olivier Leroy:	r$> g <- function(x) {x <- 10; y<- 10 ;UseMethod("g")}
     32 
     33 r$> g()
     34 Error in UseMethod("g") :
     35   no applicable method for 'g' applied to an object of class "NULL"
     36 00:48:50	Derek Sollberger:	Replying to "# Simpsons reference..."
     37 
     38 > # group generics example
     39 > 5 + as.roman(2)
     40 [1] VII
     41 00:51:34	Derek Sollberger:	Replying to "r$> g <- function(x)..."
     42 
     43 > g <- function(x) {
     44 +     x <- 10
     45 +     y <- 10
     46 +     UseMethod("g")
     47 + }
     48 > sloop::s3_methods_generic("g")
     49 # A tibble: 0 × 4
     50 # ℹ️ 4 variables: generic <chr>, class <chr>,
     51 #   visible <lgl>, source <chr>
     52 > g.default <- function(x) c(x = x, y = y)
     53 > sloop::s3_methods_generic("g")
     54 # A tibble: 1 × 4
     55   generic class   visible source    
     56   <chr>   <chr>   <lgl>   <chr>     
     57 1 g       default TRUE    .GlobalEnv
     58 00:51:53	Olivier Leroy:	Reacted to "> g <- function(x) {..." with 👍
     59 00:52:05	Diana Garcia Cortes:	Reacted to "> g <- function(x) {..." with 👍
     60 01:06:12	Diana Garcia Cortes:	I guess we can say that polymorphism is implemented in R relying on methods correctly named and an mistery UseMethod() function
     61 01:06:45	Olivier Leroy:	end
     62 ```
     63 </details>