adding R codes for new method