Adding R implementation