  A problem in representation theory of $p$-adic groups is the computation of
the \textit{Casselman basis} of Iwahori fixed vectors in the spherical
principal series representations, which are dual to the intertwining integrals.
We shall express the transition matrix $(m_{u,v})$ of the Casselman basis to
another natural basis in terms of certain polynomials which are deformations of
the Kazhdan-Lusztig R-polynomials. As an application we will obtain certain new
functional equations for these transition matrices under the algebraic
involution sending the residue cardinality $q$ to $q^{-1}$. We will also obtain
a new proof of a surprising result of Nakasuji and Naruse that relates the
matrix $(m_{u,v})$ to its inverse.
