modify R loop