The easiest way to work with PCA in R is by using the built-in functions princomp() and prcomp().
Providing a code snippet, in my opinion, would not be beneficial. However, I recommend you check out the following two pages which go into details on the topic of PCA and R with clear examples: