Let $R$ be a PID.
I want to find an injective but not surjective $R$-module homomorphism $\varphi:R^n\to R^n$ for some $n\geq 1$.
I can find injective but not surjective ring homomorphism (for $n=1$). For example, we can take $F$ as a field and consider $R=F[x]$. We can define $f:F[x]\to F[x]$ by letting $f(a)=a$ for all $a\in F$ and $f(x)=x^2$, where this example was given by @egreg, cf. here.
By when we take the $R$-module structure (or the scalar multiplication) into account, the ring homomorphism $f$ defined above is no longer a $R$-module homomorphism.
Can someone give me an example or tell me how to modify the $f$ above such that it becomes an $R$-module homomorphism? Thanks for help.
There are already examples for $n=1$, i.e. the regular module over $R$. Since you want your map $\varphi: R \to R$ to be $R$-linear (this is another way of saying that $\varphi$ is an $R$-module homomorphism), the map is completely determined by where you send $1$: $$ \varphi(r) = \varphi(r \cdot 1) = r \,\varphi(1). $$
Some immediate examples where $\varphi$ is injective but not surjective:
For a field $F$, so that $R = F[x]$ is a PID, and any $d \in \mathbb{N}$, $$ \varphi: F[x] \to F[x], \qquad 1 \mapsto x^d $$
For $R = \mathbb{Z}$ and any $n \neq 0$,
$$ \varphi: \mathbb{Z} \to \mathbb{Z}, \qquad 1 \mapsto n $$
For $R = \mathbb{Z}/m$ and any $n \in \bigl( \mathbb{Z}/m \bigr)^\times$, i.e. $\gcd(m, n) = 1$, $$ \varphi: \mathbb{Z}/m \to \mathbb{Z}/m, \qquad 1 \mapsto n $$