Imported from https://github.com/neurodata/R-RerF