updated r code