Uniformly approximating a function of vanishing variation by functions of vanishing gradient Let us say that a bounded smooth function $f:\mathbb{R}\rightarrow\mathbb{R}$ has vanishing variation at infinity (or satisfies "property $A$" for short) if, for any $r\neq 0$, we have
$$\lim_{x\rightarrow\infty}\frac{|f(x+r)-f(x)|}{|r|} = 0.$$
In particular this means that
$$\lim_{r\rightarrow 0}\left(\lim_{x\rightarrow\infty}\frac{|f(x+r)-f(x)|}{|r|}\right) = 0.$$
An example of such a function is any smooth function whose gradient vanishes at infinity (or satisfies "property $B$" for short): that is,
$$\lim_{x\rightarrow\infty}\left(\lim_{r\rightarrow 0}\frac{|f(x+r)-f(x)|}{|r|}\right) = 0.$$
On the other hand, there are functions satisfying property $B$ that do not satisfy property $A$. One type of example is any smooth function that has a limit as $x\rightarrow\infty$ but whose derivative does not go to zero; however note that such functions can always be approximated in the uniform norm by a sequence of functions satisfying property $A$.
Question: can any function satisfying $A$ be approximated in the uniform norm by a sequence of functions satisfying $B$? More precisely: given any $f$ satisfying $A$, can we find a sequence of functions $(f_i)$ satisfying $B$ such that for any $\epsilon > 0$, $||f-f_i||_\infty<\epsilon$ for all $i$ sufficiently large?
 A: Let $F(x) = \exp(f(\log x))$. Then $f$ has property A if and only if $$\frac{F(\lambda x)}{F(x)} = \exp(f(\log x + \log \lambda) - f(\log x)) \to \exp(0) = 1$$ as $x \to \infty$ for any $\lambda > 0$, that is, $F$ is slowly varying at infinity.
Once we realise this, we open the book by Bingham, Goldie and Teugels and search for the result that we need. This time this is Theorem 1.3.1, which tells us that $f$ has property A if and only if $$f(x) = a(x) + \int_{x_0}^{x} b(y) dy$$ for some $x_0$, some $a(x)$ which converges as $x \to \infty$ and some $b(y)$ which converges to zero as $y \to \infty$.
Let $A$ be the limit of $a(x)$ as $x \to \infty$, and consider $$g(x) = A + \int_{x_0}^x b(y) dy.$$ Then $g$ has property B and $f(x) - g(x)$ converges to zero as $x \to \infty$. This is essentially what we want: simply define $$f_n(x) = \phi(x - n) g(x) + (1 - \phi(x - n)) f(x),$$ where $\phi$ is smooth, $\phi = 0$ on $(-\infty, 0]$, $\phi = 1$ on $[1, \infty)$ and $0 \leqslant \phi \leqslant 1$. It is then easy to see that $f_n$ has property B, and $\|f - f_n\|_\infty \le \sup\{|f(x) - g(x)| : x \geqslant n\} \to 0$ as $n \to \infty$.

Edit: If, as suggested in the comment below, we assume that $\operatorname{diam} f(B(x, 1)) \to 0$ as $x \to \infty$, then the solution is much simpler (here $B(x, 1)$ is the unit ball centred at $x$). Consider a smooth function $\phi$ supported in the unit ball and with total mass $1$, and consider $g = f * \phi$. Then $$ |g(x) - f(x)| = \left|\int_{B(x, 1)} (f(y) - f(x)) \phi(y - x) dy\right| \leqslant \operatorname{diam} f(B(x, 1)) \|\phi\|_1 $$ and $$\begin{aligned}|g'(x)| & = \left|\int_{(x, 1)} f(y) \phi'(y - x) dy\right| \\ & = \left|\int_{(x, 1)} (f(y) - f(x)) \phi'(y - x) dy\right| \leqslant \operatorname{diam} f(B(x, 1)) \|\phi'\|_1 . \end{aligned}$$ Therefore, defining $f_n$ as in the original answer, we get the desired result.
This answer works in higher dimensions as well. The difficult part in the original answer was getting a uniform limit in $r$, which is a variant of the Karamata–Korevaar uniform convergence theorem. (I did not check if there are higher-dimensional analogues of this result).
