Every couple of months a new version of R is introduced which requires updating installed packages. I tend to only update a package when I face an error message asking me to update the package. And, when I do update it, I tend to leave the package installed an earlier version on my computer taking up space. About 3 GB were sitting in my Version 3.5 folder.
The attached code is designed to update all packages to the latest version of R. I am a bit leery of deleting files from R, so once the packages have been updated, I recommend manually deleting files from folders of previous versions of R.