Consider the following function, where below $r$ is a fixed real number, and $q$ is a positive integer
$$f(q) = \sum_{\substack{k = 1 \\ (k, q) = 1}}^{q} e^{\frac{2 \pi i k r}{q}}$$ I wished to determine the asymptotic behavior of this function as $q \rightarrow \infty$, for fixed $r$. When $r$ is an integer, I note that the above sum becomes the Ramanujan sum $c_q(r)$ which is $O(1)$ (since $|c_q(r)| \leq \sigma(r)$)
However for general $r$, it's not at all clear to me how to concretely bound this function, beyond the naive bound that $$f(q) \leq \phi(q)$$ I have a heuristic to think that $$f(q) = O(\sqrt{\phi(q)})$$ since we can think of $f(q)$ as a sum of $\phi(q)$ "random" exponential terms, which would have an expectation value of $O(\sqrt{\phi(q)})$. However, I am not sure how to make this argument rigorous.
If $r$ is not an integer, we can rewrite the sum using geometric series: \begin{align*} \sum_{\substack{0\le k<q \\ (k, q) = 1}} e^{2 \pi i k r/q} &= \sum_{k=0}^{q-1} e^{2 \pi i k r/q} \sum_{d\mid(k,q)} \mu(d) \\ &= \sum_{d\mid q} \mu(d) \sum_{j=0}^{q/d-1} e^{2 \pi i j r d/q} \\ &= \sum_{d\mid q} \mu(d) \frac{e^{2 \pi i r}-1}{e^{2 \pi i r d/q}-1} \\ &= (e^{2 \pi i r}-1) \sum_{d\mid q} \frac{\mu(d)}{e^{2 \pi i r d/q}-1} = (e^{2 \pi i r}-1) \sum_{d\mid q} \frac{\mu(q/d)}{e^{2 \pi i r/d}-1}. \end{align*} When $d\ge r$, say, we have $e^{2 \pi i r/d}-1 = 2 \pi i \frac rd + O_r(\frac1{d^2}) = 2 \pi i \frac rd (1+O_r(\frac1d))$. Therefore* \begin{align*} \sum_{\substack{0\le k<q \\ (k, q) = 1}} e^{2 \pi i k r/q} &= (e^{2 \pi i r}-1) \sum_{d\mid q} \mu(\tfrac qd) \frac d{2 \pi i r} (1+O_r(\tfrac1d)) \\ &= \frac{e^{2 \pi i r}-1}{2\pi ir} \sum_{d\mid q} \big( d \mu(\tfrac qd) + O_r(1) \big) \\ &= \frac{e^{2 \pi i r}-1}{2\pi ir} \phi(q) + O_r(\tau(q)), \end{align*} where $\tau(q)$ is the number of divisors of $q$. So, surprisingly, the asymptotic behavior really is like $\phi(q)$. (Numerical experiments confirm this asymptotic formula.)
*I cheated with the terms $d<r$, but I think that this just gives a $O_r(1)$ error.