tidyverse / purrr

A functional programming toolkit for R
https://purrr.tidyverse.org/
Other
1.28k stars 272 forks source link

Implemented S7 by swapping the `rate` class and subclasses from S3 #1154

Open VisruthSK opened 3 weeks ago

VisruthSK commented 3 weeks ago

Fixes #1129

Notes/caveats:

I changed some tests to account for the new syntax of S7 objects--eg. changing $ to @. Additionally, the new constructor for rate objects is called just rate() instead of new_rate() so I also changed some variable names in the tests to not conflict with that.

I don't like line 71 in rate.R. There, I have a subclass with a different default value of a property than the parent class. I want to override the super's default value for max_times, but when I just include max_times as a property of the subclass with a different default, the constructed object's value goes to that of the parent. (3 instead of Infinity for rate_delay).

I got around it by checking if max_times was supplied as an argument and providing the correct default value if it wasn't.

I didn't write change any documentation, so if that needs to be changed I will fix that. The changes are mainly internal, but it may be good to document what certain things are doing so that if S7 changes the purpose of the code can still be understood.

Mentioning @kbodwin since this PR is part of the awesome Independent Study: Advanced R with Dr Bodwin this quarter!