For $\rm\ f = A-B\in R[x]\:,\:$ it is equivalent to ask if $\rm\ f(r) = 0\ $ for all $\rm\: r\in R\ \Rightarrow\ f = 0\:,\: $ i.e. if $\rm\:f\ $ is zero as a function then is $\rm\:f\ $ zero as a formal polynomial, i.e. are all its coefficients zero? This is true if $\rm\:R\:$ is an integral domain of cardinality greater than the degree of $\rm\:f\:,\:$ e.g. if $\rm|R|$ is infinite, but it may fail otherwise, e.g. $\rm\ x^p = x\ $ for all $\rm\: x\in \mathbb Z/p\ $ by Fermat's little theorem, but $\rm\ x^p \ne x\ $ in $\rm\: \mathbb Z/p\:[x]\:.$
Remark $\ $ In fact a ring $\rm\: D\:$ is a domain $\iff$ every nonzero polynomial $\rm\ f(x)\in D[x]\ $ has at most $\rm\ deg\ f\ $ roots in $\rm\:D\:.\:$ For the simple proof see my post here, where I illustrate it constructively in $\rm\: \mathbb Z/m\: $ by showing that, $\:$ given any $\rm\:f(x)\:$ with more roots than its degree,$\:$ we can quickly compute a nontrivial factor of $\rm\:m\:$ via a $\rm\:gcd\:$. The quadratic case of this result is at the heart of many integer factorization algorithms, which try to factor $\rm\:m\:$ by searching for a nontrivial square root in $\rm\: \mathbb Z/m\:,\:$ e.g. a square root of $1$ that is not $\:\pm 1$.