···22Title: An S7 Showcase
33Version: 0.0.0.9000
44Authors@R:
55- person("Visruth", "Srimath Kandali", , "visruth@gmail.com", role = c("aut", "cre"),
55+ person("Visruth", "Srimath Kandali", , "public@visruth.com", role = c("aut", "cre"),
66 comment = c(ORCID = "0009-0005-9097-0688"))
77Description: A toy package designed to showcase and serve as a
88 reference/tutorial for S7 development. To be used in conjunction with
+2-2
R/big_num.R
···5050 getter = function(self) self@state$head,
5151 setter = function(self, value) {
5252 # TODO: kick up to error?
5353- warning("@head should not be set manually. Maybe you meant to use `append_to_start()`?", call. = FALSE)
5353+ warning("@head should not be set manually. Did you mean to use `append_to_start()`?", call. = FALSE)
54545555 my_env <- self@state
5656 my_env$head <- value
···125125is_even <- new_generic("is_even", c("x"))
126126method(is_even, big_num) <- function(x) x@head@VALUE %% 2 == 0
127127128128-# TODO: rewrite to be external generic?
128128+# TODO: rewrite to be external generic? `base::append()`
129129bn_append <- new_generic("bn_append", c("x", "ll"))
130130method(bn_append, list(node, linked_list)) <- function(x, ll) {
131131 suppressWarnings({
···276276277277I wrote the S7 implementation first, and have since expanded to a S3 and S4 implementation (and might add a rough R6 one too?). These three versions (S3, S4, S7) have rough feature parity, but part of this project is to highlight the benefits of S7 so there are things you can't do (or at least, can't do as easily) in the other OOP structures.
278278279279-So why BigNum specifically? Well, mostly because it's easy to implement. The BigNum project is taken from my CSC 203 class, a OOP course at Cal Poly. I already had all the methods implemented (in Java) and a clear idea of what I needed to do and how, with the main work being in porting design to R as opposed to novel thought. This greatly simplified dev time since I had a reference implementation to use. **Importantly,** **this (along with my lack of experience) could lead to unidiomatic R/S7 code and design patterns.** **If you notice anything strange, please open an issue/PR!**
279279+So why BigNum specifically? Well, mostly because it's easy to implement. The BigNum project is taken from my CSC 203 class, an OOP course at Cal Poly. I already had all the methods implemented (in Java) and a clear idea of what I needed to do and how, with the main work being in porting design to R as opposed to novel thought. This greatly simplified dev time since I had a reference implementation to use. **Importantly,** **this (along with my lack of experience) could lead to unidiomatic R/S7 code and design patterns.** **If you notice anything strange, please open an issue/PR!**
280280281281-I haven't developed an R package before, and so that provided additional motivation for me to create this project. That also means that this package is certainly written sub-optimally. Additionally, my experience with S7 is extremely limited–I would be extremely grateful for any and all R sourcerers who can rain issues and pull requests down from the heavens fixing all my mistakes :)
281281+I haven't developed an R package before, and so that provided additional motivation for me to create this project. That also means that this package is certainly written sub-optimally. Additionally, my experience with S7 is extremely limited--I would be extremely grateful for any and all R sourcerers who can rain issues and pull requests down from the heavens fixing all my mistakes :)
282282283283## Acknowledgements
284284285285-Thank you Dr T and Dr Bodwin for helping with this project!
285285+Thank you Dr Theobold and Dr Bodwin for helping with this project!
286286287287## References
288288
+1-1
tests/testthat/test-big_num.R
···11rmpfr_test_multiplication <- function(string_num_1, string_num_2) {
22- # using Rmpfr to check big_num's accuracy
22+ # using Rmpfr to verify big_num's accuracy
33 num <- Rmpfr::mpfr(string_num_1, 200) * Rmpfr::mpfr(string_num_2, 200)
44 string_num_solution <- as(num, "character")
55