Analysis of the R-matrix method on Lagrange meshes