There are 3 issues at play here.
The first is that the test actually computes 2 statistics, $R_1$ and $R_2$, namelly the sum of ranks for sample 1, and sample 2. The "custom" is to chose as the statistic reported $Min(R_1,R_2)$; but in fact, one could chose either, as they carry exactly the same information (remember that $R_1+R_2=\frac {(n_1+n_2+1).(n_1+n_2)} {2}$). So if you see $W=0$, that means that "the other W" is quite large. And remember also that, under the null, W will not be equal to 0, but instead to $\frac {(n_1+n_2+1).(n_1+n_2)} {4}$, so $W=0$ is in fact very extreme.
The 2nd is that in your case, all the values of the 2nd sample are larger than all values of the first. That is as "extreme" (against the null) as 2 samples could get. Now if you only had run wilcox.test(b,a), the p-value would have been identical, but W would be larger (36 for your example).
The 3rd, and the major one, is that wilcox.test does not return a sum of ranks. If it did, for your example with 6 values in each sample, the sum of ranks statistic should be in the interval $[21,57]$. It is indeed impossible for a true sum of ranks to be 0 (that would imply that the sample had 0 values?!?). What this R function does instead is subtract the minimum possible value of the statistic (in your example, 21) from the actual, true sum of ranks. It does this, so that what it returns is actually the Mann-Whitney U statistic (remember that $U_1=R_2-\frac {n_2(n_2+1)} {2}$, and vice-versa for $U_2$. But it calls it W (should really call it U), adding to the confusion, as you examplify (the function is called wilcox.test(), but returns the Mann-Whitney statistic?? Yes, they are equivalent, but...)
In fact, if I use other software, I never get $W=0$, for your example, but instead $W=21$, as it should be (e.g. Minitab, this online calculator, or the Real Statistics Excel add-on package, all return $W=21$). And I get W=57 when I test B against A, again as it should be.
a = c(38.9, 61.2, 73.3, 21.8, 63.4, 64.6, 48.4, 48.8, 48.5);b = a+200;wilcox.test(a,b)
. @ChristianHennig $\endgroup$