+ - 0:00:00
Notes for current slide
Notes for next slide

Advanced R Ch16 - Tradeoffs

@_TanHo

2020-07-07

1 / 7

Outline

1) What does Hadley think are the main trade-offs?

2) Dive into ffscrapr, a package I'm working on that uses S3

2 / 7

Outline

1) What does Hadley think are the main trade-offs?

2) Dive into ffscrapr, a package I'm working on that uses S3

(and figure out whether I should have used R6/S4 instead...)

2 / 7

Hadley on S3 vs S4

  • S3 is informal, whereas S4 is formal
3 / 7

Hadley on S3 vs S4

  • S3 is informal, whereas S4 is formal

  • S3 relies on conventions (i.e. informal rules) because it is flexible and easily abused, whereas S4 has structure and cannot be as easily abused.

3 / 7

Hadley on S3 vs S4

  • S3 is informal, whereas S4 is formal

  • S3 relies on conventions (i.e. informal rules) because it is flexible and easily abused, whereas S4 has structure and cannot be as easily abused.

  • S4 is therefore better in larger, more rigorous projects that are established (i.e. Bioconductor, DBI)

3 / 7

Hadley on S3 vs R6

  • R6 is encapsulated, whereas S3 is functional
4 / 7

Hadley on S3 vs R6

  • R6 is encapsulated, whereas S3 is functional

  • S3 namespacing is global, R6 is local to the object

4 / 7

Hadley on S3 vs R6

  • R6 is encapsulated, whereas S3 is functional

  • S3 namespacing is global, R6 is local to the object

  • S3 is functional and therefore feels natural to the average R user, R6 does not

4 / 7

Hadley on S3 vs R6

  • R6 is encapsulated, whereas S3 is functional

  • S3 namespacing is global, R6 is local to the object

  • S3 is functional and therefore feels natural to the average R user, R6 does not

  • R6 has state where S3 does not (accumulator programming/threading state is easy to accomplish in R6 but hard in S3)

4 / 7

ffscrapr

"An R Client for Fantasy Football League APIs"

The goal of this package is to abstract the code required to call various Fantasy Football APIs (i.e. MFL, Sleeper, Fleaflicker, ESPN, Yahoo, potentially other platforms) and create methods that handles required authentication, forms appropriate calls, and returns tidy and predictable data which can be easily connected to other data sources.

5 / 7

ffscrapr

"An R Client for Fantasy Football League APIs"

The goal of this package is to abstract the code required to call various Fantasy Football APIs (i.e. MFL, Sleeper, Fleaflicker, ESPN, Yahoo, potentially other platforms) and create methods that handles required authentication, forms appropriate calls, and returns tidy and predictable data which can be easily connected to other data sources.

In other words, a DBI-like interface where you don't need to know the nuts and bolts of each platform (i.e. MySQL, ODBC, SQL Server, PostgreSQL), and instead just need to know a little about the DBI package to get the data you want.

5 / 7

ffscrapr

"An R Client for Fantasy Football League APIs"

The goal of this package is to abstract the code required to call various Fantasy Football APIs (i.e. MFL, Sleeper, Fleaflicker, ESPN, Yahoo, potentially other platforms) and create methods that handles required authentication, forms appropriate calls, and returns tidy and predictable data which can be easily connected to other data sources.

In other words, a DBI-like interface where you don't need to know the nuts and bolts of each platform (i.e. MySQL, ODBC, SQL Server, PostgreSQL), and instead just need to know a little about the DBI package to get the data you want.

Code here: https://github.com/DynastyProcess/ffscrapr

5 / 7

ffscrapr - motivations

1) Teach myself about R packages

6 / 7

ffscrapr - motivations

1) Teach myself about R packages so that I can start looking at golem with an unbiased opinion

6 / 7

ffscrapr - motivations

1) Teach myself about R packages so that I can start looking at golem with an unbiased opinion

2) Teach myself about unit testing, CI/CD, and CRAN

6 / 7

ffscrapr - motivations

1) Teach myself about R packages so that I can start looking at golem with an unbiased opinion

2) Teach myself about unit testing, CI/CD, and CRAN

3) Share experience I have in Fantasy Football APIs so that others can build on it without learning the nuts and bolts

6 / 7

ffscrapr - motivations

1) Teach myself about R packages so that I can start looking at golem with an unbiased opinion

2) Teach myself about unit testing, CI/CD, and CRAN

3) Share experience I have in Fantasy Football APIs so that others can build on it without learning the nuts and bolts

... and unexpectedly,

4) Experiment with OOP?

6 / 7

Live Coding (gulp!)

Some guiding questions:

  • Why S3?

  • What does something similar in R6 look like?

  • What could R6 do that S3 doesn't? (hint: state)

Potentially interesting:

7 / 7

Outline

1) What does Hadley think are the main trade-offs?

2) Dive into ffscrapr, a package I'm working on that uses S3

2 / 7
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow