Changing code to use rpy2