Skip to content

Commit

Permalink
add s4 emojis to pdf, replace r6 emojis
Browse files Browse the repository at this point in the history
  • Loading branch information
henningsway committed Dec 25, 2020
1 parent 82ed528 commit a40165f
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 12,344 deletions.
6 changes: 4 additions & 2 deletions 14_R6.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,13 @@ my_charging_account$balance
__[Q2]{.Q}__: Create an R6 class that represents a shuffled deck of cards. You should be able to draw cards from the deck with `$draw(n)`, and return all cards to the deck and reshuffle with `$reshuffle()`. Use the following code to make a vector of cards.

```{r}
suit <- c("", "", "", "")
suit <- c("SPADE", "HEARTS", "DIAMOND", "CLUB")
value <- c("A", 2:10, "J", "Q", "K")
cards <- paste0(rep(value, 4), suit)
cards <- paste(rep(value, 4), suit)
```

*(This question was altered slightly to avoid the unicode characters.)*

__[A]{.solved}__: Our new `ShuffledDeck` class will use `sample()` and positive integer subsetting to implement the reshuffling and drawing functionality. We also add a check, so you cannot draw more cards than there are left in the deck.

```{r}
Expand Down
9 changes: 7 additions & 2 deletions 15_S4.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,20 @@ setMethod("show", "Person", function(object, y) {
## Method dispatch
<!-- 15.5 -->

__[Q1]{.Q}__: Draw the method graph for `f(😅, 😽)`.
```{r, include=FALSE}
source("emoji.R")
code <- function(...) paste0("`", ..., "`")
```

__[Q1]{.Q}__: Draw the method graph for `r paste0(code("f("), emoji("sweat_smile"), ", ", emoji("kissing_cat"), code(")"))`.

__[A]{.solved}__: Look at the graph and repeat after me: "I will keep my class structure simple and use multiple inheritance sparingly".

```{r, echo = FALSE, out.width='350pt'}
knitr::include_graphics("images/s4/method_dispatch1.png", dpi = 300)
```

__[Q2]{.Q}__: Draw the method graph for `f(😃, 😉, 😙)`.
__[Q2]{.Q}__: Draw the method graph for `r paste0(code("f("), emoji("smiley"), ", ", emoji("wink"), ", ", emoji("kissing_smiling_eyes"), code(")"))`.

__[A]{.solved}__: We see that the method graph below looks simpler than the one above. Relatively speaking, multiple dispatch seems to introduce less complexity than multiple inheritance. Use it with care, though!

Expand Down
Loading

0 comments on commit a40165f

Please sign in to comment.