Migrated R to C++ code.