Please don’t

# Check if dplyr installed
if (!"dplyr" %in% row.names(installed.packages())) {
  # install if not
  install.packages("dplyr")
}
nuh_uh
nuh_uh

Why not?

“This works fine for a while. But the problem with this is that the default has you installing things into a cache that’s shared among every project on your system.”

It’s also considered rude to make changes to a user’s system-level package setup.

More importantly, DevOps aims to help you make things that don’t break, installing packages without versions specified does not prevent things from breaking in the future.