How to move folder where non-base packages are installed (Windows)

My work installation has OneDrive. So everything under Documents is being copied up to SharePoint.
That is not required for my non-base packages under Documents/R/win-library.
And results in huge activity when I upgrade R/packages.

So how do I change which folder is used please?

I have always accepted defaults at installation time, so I don't know where the location Documents/R/win-library/4.1 is configured for my current R.
I have seen there is a move packages function in installr ( copy.packages.between.libraries) which I assume will help me. But what else do I need to configure to move the packages to C\R for instance.

You can change the default library folder by setting your R_LIBS_SITE environmental variable on a .Reviron or .Rprofile file. For example:

# In a .Renviron file you can set it by adding a line like this one with the desired location 
R_LIBS_SITE="C:\\Program Files\\R\\R-4.1.1\\library"

For a more detailed explanation, you can read this blog post

Thank you for this (the reply and the article)
I will run through it and give you any feedback

Thank you
I ended up adding R_LIBS_USER to my user environment (value C:\R\win-library\4.1) in WINDOWS
The good news is that both:

  1. means that the old reference to $HOME\R\win-library\4.1) no longer comes up when I run .libPaths()
  2. the new location is the default to install to

I had been been thinking of copying package files from the old location to the new. But in fact I just let RStudio install them to the new location

If they have been compiled under the same R version you are currently using there is no problem with doing that, if they haven't (like when you update R), you just need to run update.packages(checkBuilt = TRUE) afterwards.