Take out a factor r from everything on the bottom, then divide the top and the bottom of the fraction by R.
I defined s=R/r, you don't really need, you could differentiate directly wrt R but it makes it slightly simpler.
To see why its valid to just differentiate the bottom of the fraction when looking for turning points, consider a function f(x)=1/g(x) differentiate both sides, then f'(x)=-g'(x)/(g(x)^2), so if g'(x)=0, f'(x)=0, where ' means the derivative of.
Edit: I'm not sure what level of maths you've studied, so if you've not met the chain rule in differentiation (I think it's C3/4?) you'll probably be completly lost by what I've done above.