Retraction for rings?

For abelian groups, the existence of left inverse or right inverse of a homomorphism can be characterized by looking at whether the image or kernel splits the group. Is there an analogous characterization for ring homomorphisms? Specifically, if $$f:R\rightarrow S$$ be a ring homomorphism, when does there exist a ring homomorphism $$g:S\rightarrow R$$ such that $$f\circ g=\mathrm{Id}_S$$ or $$g\circ f=\mathrm{Id}_R$$ ?

Edit: Let's restrict to commutative rings for now.

Consider just the case of left inverses. Here is the sort of thing that can go wrong: take $$f : k \to k[x]/f(x)$$. Then a left inverse exists iff there exists $$r \in k$$ such that $$f(r) = 0$$, and e.g. if $$k$$ is a non-algebraically closed field this won't exist most of the time. More generally we can take maps like $$f : \mathbb{Z} \to \mathbb{Z}[x_1, ..., x_n]/(f_1, f_2, ..., f_m)$$ and we see that the problem of determining whether there exists a left inverse is at least as hard as the problem of determining whether a system of Diophantine equations has an integer solution, which is known to be undecidable in a particular sense by Matiyasevich's theorem. These examples show in particular that it doesn't suffice to assume that $$f$$ is a monomorphism or even that it makes $$S$$ a finite rank free $$R$$-module.