R functions for rmscca