R is an integral domain and every module we talk about is an R-module. If a module is finitely generated then obviously every element of the module can be written as finite R-linear combination of the set of generators. I observe that this expression might not be unique due to which the module could fail to be free. What has this got to do with the rank? More specifically, how exactly is rank of a module defined.
Being finitely generated says the module can be spanned by finitely many elements, but rank refers to the maximum number of elements which are linearly independent in the module.
These two conditions sound similar, and indeed they coincide in linear algebra, but they can be different.
See https://mathoverflow.net/a/30024/19965 and also maybe section 1c of Lectures on modules and rings for more info.