I found error message of "Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : namespace ‘xfun’ 0.31 is already loaded, but >= 0.34 is required"

the error tells you the names of packages which you have currently loaded in your session; so cannot be updated/installed while that is the case.

You need to restart R; so that packages aren't loaded; and then try to install again.
Often people get into trouble because they load their last workspace on start and this populates with their packages.

Disable this behaviour
Tools -> Global options -> Restore .RData into workspace at startup
then restart.
then install what you need to install. or do update.packages etc.

You can reenable it after this but I wouldnt if I was you