It would be better if you would have provided a minimal working example of your Rmd. As the provided code works fine I could just guess that you forgot to attach the packages inside your Rmd (having them attached to your R session is not enough, as the Rmd is rendered in a fresh and clean R session). Therefore make sure that your Rmd includes a code chunk to attach the packages, i.e.