Error: could not find function "install.packages" for R markdown

This suggest you have a .Rprofile file with an install command on it. Look for it and remove the command