How to calculate $\int_0^{2\pi}\frac{\cos(\phi)-R}{1-2R\cos(\phi)+R^2}\cos(n\phi)~d\phi$? I wish to calculate
$$I(R)=\int_0^{2\pi}\frac{\cos(\phi)-R}{1-2R\cos(\phi)+R^2}~\cos(n\phi)~d\phi,$$
where $n\in\mathbb{N}$, $R\in[0,1)$.
Based on trial and error from plugging numbers into Wolfram alpha I think the answer is
$$I(R)=\begin{cases}
0, & n=0, \\
\pi R^{n-1}, & n\ge1.
\end{cases}$$
However, I don't know how to show this more rigorously. Do you know how to calculate the above integral, and do you know if my formula is correct?

Given $R\in[0,1)$, there is a unique function with the following Fourier series:
$$ \sum_{n\geq 1}R^n \cos(n\theta) = \text{Re}\sum_{n\geq 1} R^n e^{in\theta} = \text{Re}\left(\frac{R e^{i\theta}}{1-R e^{i\theta}}\right)= \text{Re}\left(\frac{R e^{i\theta}(1-R e^{-i\theta})}{(1-R e^{i\theta})(1-Re^{-i\theta})}\right)$$
and such function is precisely
$$ \frac{R\cos\theta-R^2}{1-2R\cos\theta+R^2}. $$
