Restarting R session

Hello. When I try to install many packages in a row, I often get the following error message:

One or more of the packages that will be updated by this installation are currently loaded. Restarting R prior to updating these packages is strongly recommended.

RStudio can restart R and then automatically continue the installation after restarting (all work and data will be preserved during the restart)

Do you want to restart R prior to installing?

Could you, please, tell me, how to succesfully install packages without receiving such a error?