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?

Define: $z=e^{i\phi}$
$$\cos(\phi)=\frac{1}2\left(z+\frac{1}z \right),~~~~\cos(n\phi)=\frac{1}2\left(z^n+\frac{1}{z^n} \right),~~~~d\phi=\frac{1}{iz}dz$$
If $n=0$,
$$\begin{align}
I&=\frac{1}{2i}\oint \frac{z^2-2Rz+1}{z(z-R)(1-Rz)}dz=\frac{1}{2i}\cdot 2\pi i\cdot \left(Res[z=0]+Res[z=R]\right)\\
\\
&=\pi\cdot\left( -\frac{1}R+\frac{1-R^2}{R(1-R^2)}\right)=0
\end{align}$$
If $n\ge 1$
$$\begin{align}
I&=\frac{1}{4i}\oint \frac{(z^2-2Rz+1)z^{n-1}}{(z-R)(1-Rz)}dz+\frac{1}{4i}\oint \frac{(z^2-2Rz+1)}{z^{n+1}(z-R)(1-Rz)}dz=I_1+I_2\\
\\
I_1&=\frac{1}{4i}\cdot 2\pi i\cdot Res[z=R]=\frac{\pi}2R^{n-1}\\
\\
I_2&=\frac{1}{4i}\cdot 2\pi i\cdot \left(Res[z=0]+Res[z=R] \right)=\frac{\pi}2 \left( -\frac{1}{R^{n+1}}+R^{n-1}+\frac{1}{R^{n+1}} \right)\\
\\
I&=\pi\cdot R^{n-1}
\end{align}$$
