updated r script