(I'm using the word "field" in the mathematical sense; base fields/corpora which R already uses include the real and complex numbers.)
I'm interested in allowing some other base fields/corpora (like F₅, which is modular arithmetic in base 5). To do that I would need to
- define a new data type
- overload the relevant operators (
+,*, and maybe more) - maybe something else? e.g., integrate with other functionality?
So, how does one define a new data type or overload operators in R?
I found Hadley Wickham's devtools wiki an invaluable resource for getting started with classes in R. In particular, read the sections on:
Here is a starting point that illustrates some of the concepts in
S3classes. Let's call your new classf5. At a minimum, you would probably want to create methods for:as.f5is.f5+.f5print.f5Some code (using
digitsBasein packageGLDEXto do the base conversion):