Fix error in r computation