There is a nice criterion that is usually applied in this situation.
A is flat over $R$ if the Krull dimension of the fiber ring $A_{\mathfrak{P}}/\mathfrak{P}$ for all prime ideals $\mathfrak{P} \subset R$ is $n-r$ (or the fiber is empty). In scheme theoretic language, the fibers either have the expected dimension (are complete intersections) or are empty. This is what is called a relative global complete intersection here https://stacks.math.columbia.edu/tag/00SK. Flatness follows from https://stacks.math.columbia.edu/tag/00SW.
This is a generalization of the criterion you cited when $r=1$. In that case the fibers of $Spec(R[x_1, \ldots, x_n]) \to Spec(R)$ are affine spaces over a field (so integral) and the condition ensures that the restriction of the polynomial $f$ to every fiber over some closed and open subset $U \subset Spec(R)$ is nonzero, so it must cut a closed subset of the fiber of dimension $n-1$ (or empty if it restricts to a constant). The idempotent comes from the fact that if $Spec(R)$ is not connected, then we can allow the preimage over the complement of this open and closed to be just isomorphic to the whole affine space $\mathbb{A}^n_{Spec(R) \setminus U}$, ($f$ is allowed to be identically $0$ on $Spec(R) \setminus U$).