$\frac{1}{2r}\int_{x-r}^{x+r}f(t)dt \to g(x)$ uniformly when $r\rightarrow \infty$, then $g(x)=ax+b$

We have

$$\frac{1}{2r}\int_{x-a-r}^{x-a +r} f(t)\, dt + \frac{1}{2r}\int_{x+a-r}^{x+a+r} f(t)\, dt \\= \frac{r+a}{r}\frac{1}{2(r+a)}\int_{x - (r+a)}^{ x + (r+a)}f(t) \, dt + \frac{r-a}{r}\frac{1}{{2(r-a)}}\int_{x - (r-a)}^{ x + (r-a)}f(t) \, dt $$

Taking limits with $a$ fixed we get $g(x- a) + g(x+a) = 2g(x)$ since $(r \pm a)/r \to 1$ as $r \to \infty$. Substituting with $u = x-a$ and $v = x+a$, it follows that

$$g(u) + g(v) = 2 g ((u+v)/2)$$

Now take $h(x) := g(x) - g(0)$, whence $ h(u) + h(v) = 2h((u+v)/2)$ and $h(0) = 0$.

Thus,

$$h(u+v) = h(u+v) + h(0) = 2h((u+v+0)/2) = 2h((u+v)/2) = h(u) + h(v),$$

and we see that $h$ must be a linear function. It is also continuous as the uniform limit of continuous functions.

Finally, it can be shown that a linear function with points of continuity must be of the form $h(x) = h(1)x$ and, therefore,

$$g(x) = h(x) + g(0) = h(1)x + g(0) = ax+b$$