Let $M$ be an $R$-module, $R$ a ring, and $Z$ a nonempty subset of $M$. Assume that for every $R$-module $N$ and every map $f: Z \rightarrow N$ there exists a unique $R$- linear map $\tilde{f}$ : $M \rightarrow N$ s.t.the restriction of $\tilde{f}$ to $Z$ is $f$. Show that $Z$ is a basis of $M$.
My attempt: Suppose not. Then there is an element of M which cannot be uniquely written as a linear combination of elements of Z. I think I am supposed to consider the inclusion map from Z to M and use the extended map from the hypothesis to arrive at a contradiction, but I can't see how.
Lemma 14.1 in the book above, proves this, but I can't see where $g$ comes from, or why the composition on $N$ to $N$ coincides with the identity on $N$.