Is there a simple sufficient condition for a function to depend "only on $r$"? Suppose I were to pose the following problem to a class of calculus students:

What is the magnitude of $\nabla f(x,y)$, where $f : \mathbb{R}^2 \to \mathbb{R}$ is the paraboloid function
  $$ f(x,y) = x^2 + y^2? $$

If a student produced the incorrect answer
$$ |\nabla f(x,y)| = 2x + y,$$
I might say:

No, you can tell that can't possibly be right, since it treats $x$ and $y$ on unequal footing. Think geometrically--the paraboloid has radial symmetry about the origin, so your solution should depend only on $r = \sqrt{x^2 + y^2}$.

This notion of "a function depending only on a certain function of its variables" raises the following question: when does a function $f(x,y)$ depend only on $r = \sqrt{x^2 + y^2}$, or on $|x-y|$, or on some other function $g(x,y)$ of its inputs?
More generally, given a function $f: \mathbb{R}^n \to \mathbb{R}$,  is there a simple sufficient condition for $f$ to "depend only on $g: \mathbb{R}^n \to \mathbb{R}$," that is, for there to exist a function $u: \mathbb{R} \to \mathbb{R}$ such that $f = u \circ g$? Here I am thinking of something like the Wirtinger derivatives $\partial / \partial z$ and $\partial / \partial \overline{z}$ in complex analysis, which provide simple tests for dependence only on $z$ or $\overline{z}$, (i.e., (anti)holomorphicity).
 A: Let $f:\>{\mathbb R}^n\to{\mathbb R}$ and $g:\>{\mathbb R}^n\to{\mathbb R}$ with $f(0)=g(0)=0$ be sufficiently smooth in a neighborhood $\Omega$ of $0$,  and assume that there is a smooth function $U$ defined in a neighborhood of $0$ such that
$$f(x)=U\bigl(g(x)\bigr)\qquad\forall x\in \Omega\ .\tag{1}$$
Then the chain rule immediately implies
$$\nabla f(x)=U'\bigl(g(x)\bigr)\>\nabla g(x)\qquad\forall x\in \Omega\ ,$$saying that at each point $x\in \Omega$ the two gradients necessarily point into the same direction. Now we are looking for a converse to this principle. It turns out that the  condition we found is also sufficient:
Theorem. Assume $f$ and $g$ as before, and in addition that $\nabla g(x)\ne0$ in $\Omega$. If there is a smooth function $\lambda: \>\Omega\to{\mathbb R}$ such that
$$\nabla f(x)=\lambda(x)\>\nabla g(x)\qquad\forall x\in \Omega\tag{2}$$
then $(1)$ holds for a suitable function $U$ in a maybe smaller neighborhood $\Omega'$.
Proof. Writing out $(2)$ in components we have
$$f_{.i}(x)=\lambda(x)\>g_{.i}(x)$$
for all $i\in[n]$ and therefore
$$0=f_{.ik}(x)-f_{.ki}(x)=\lambda_{.k}(x)\>g_{.i}(x)-\lambda_{.i}(x)\>g_{.k}(x)$$
for all $i$ and $k$. This says that the matrix
$$\left[\matrix{\lambda_{.1}(x)&\cdots&\lambda_{.n}(x)\cr
g_{.1}(x)&\cdots&g_{.n}(x)\cr}\right]$$
has rank $\leq1$ for all $x$, and as $\nabla g(x)\ne 0$ this means that there is a scalar function $\mu$ with
$$\nabla \lambda(x)=\mu(x)\>\nabla g(x)\qquad(x\in\Omega)\ .\tag{3}$$
Claim: The function $\lambda$ is constant on any hypersurface $S_\eta:=\{x\in\Omega\>|\> g(x)=\eta\}$.
Proof. If $\gamma: \>t\mapsto x(t)$ is a curve on such an $S_\eta$ then $\nabla g\bigl(x(t)\bigr)\cdot x'(t)\equiv0$. From $(3)$ it follows that the pullback $\hat\lambda(t):=\lambda\bigl(x(t)\bigr)$ has derivative
$$\hat\lambda'(t)=\nabla\lambda\bigl(x(t)\bigr)\cdot x'(t)=\mu\bigl(x(t)\bigr)\nabla g\bigl(x(t)\bigr)\cdot x'(t)\equiv0\ .$$
This shows that $\lambda$ is constant along $\gamma$.
We may assume that $g_{.n}(0)\ne0$. Then the map
$$\phi:\quad x=(x_1,\ldots,x_n)\mapsto y=(y_1,\ldots, y_n):=\bigl(x_1,x_2,\ldots, x_{n-1},g(x)\bigr)$$
has Jacobian $J_\phi(0)=g_{.n}(0)\ne0$ and therefore possesses a smooth inverse
$$\psi:\quad (y_1,\ldots, y_n)\mapsto (x_1,\ldots, x_n):=\bigl(y_1,\ldots, y_{n-1}, \psi_n(y)\bigr)$$
defined in a neighborhood of $y=0$. We now define the function 
$$\eta\mapsto u(\eta):=\lambda\bigl(0,\ldots,0,\psi_n(\eta)\bigr)\ ,$$
which is smooth in a neighborhood of $\eta=0$. 
Claim: For this function $u$ one has
$$\lambda(x)=u\bigl(g(x)\bigr)\tag{4}$$
in a suitable neighborhood of $x=0$.
Proof.  Consider an arbitrary point $x$ and put $g(x)=:\eta$. Then $x$ lies in $S_\eta$, and so does the point $p_\eta:=\bigl(0,\ldots,0, \psi_n(\eta)\bigr)$. Since $\lambda$ is constant on $S_\eta$ it follows that
$$\lambda(x)=\lambda(p_\eta)=u(\eta)=u\bigl(g(x)\bigr)\ .$$
Let $U$ be a primitive of $u$ with $U(0)=0$. I claim that one has $f=f^*$ with
$$f^*(x)=U\bigl(g(x)\bigr)$$
in a suitable neighborhood $\Omega'$ of $0$. For the proof it is sufficient to compute the gradient of $f^*$. By means of $(4)$ we obtain
$$\nabla f^*(x)=U'\bigl(g(x)\bigr)\>\nabla g(x)=u\bigl(g(x)\bigr)\>\nabla g(x)=\lambda(x)\>\nabla g(x)=\nabla f(x)\ .$$
A: Suppose $f,g: \mathbb{R}^n \to \mathbb{R}^m$ continuously differentiable.
Let $Df$ and $Dg$ be the derivative matrices. Then we can write $f=u(g)$ for some continuously differentiable $u:\mathbb{R}^m \to \mathbb{R}^m$ iff $Df=\lambda Dg$ always, where $\lambda$ is a continuous function $\mathbb{R}^n \to Mat(\mathbb{R}^m)$ (mxm matrices), and in fact $\lambda=Du$.
In the case $m=1$, this can be translated as $\nabla f //\nabla g$ (derivatives parallel, $\nabla f =\lambda \nabla g$).
EDIT: the above is actually wrong. Consider $f=x^2-y^2,g=x+y$. Then $\nabla f=\lambda \nabla g$ with $\lambda=2(x-y)$.
What we actually need (and this is obvious if you actually try to prove it unlike me last night) is that $\lambda$ is a function of $g$, i.e. $\nabla f=\lambda(g)\nabla g$ where $\lambda: \mathbb{R} \to \mathbb{R}$. So I have actually done little to help you solve your problem, although it may often be simpler to see whether $f$ is a function of $g$ only by looking at derivatives. You could also re-apply the check to $\lambda$ and $g$ if $\lambda$ is differentiable and keep going, if it makes it any simpler.
