(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
S3
classes. Let's call your new classf5
. At a minimum, you would probably want to create methods for:as.f5
is.f5
+.f5
print.f5
Some code (using
digitsBase
in packageGLDEX
to do the base conversion):