Migrate from reference classes to R6

This PR replaces reference classes with R6. The examples seem to work, it passes R CMD check, and checking reverse dependencies doesn't result in any errors that seem that they could be related to this change.

We don't have to merge this before the next release; I just thought I'd put this out there now.