Can not install any package in R version 4.1.2

Hi,
I uninstalled R and Rstudio from my laptop (windows 10 - operated), then after installing the new version 4.1.2, every time I install any package, I got this error message:
Error in install.packages : cannot open file 'C:/Users/xxxxxx/Documents/R/win-library/4.1/file1808276551dc/magrittr/help/figures/exposition-1.png': Permission denied

I do not know how to reset the path of the library folder. May you please help me to figure it out? Also, every time I open Rstudio, I found the environment loaded with data from the latest ran code, however, I cleaned the environment but the data are still loaded. The weird thing is that these data were loaded using the older version, how they have been recalled in the new version?

Something to add, I just checked the path to library:
.libPaths()
and I got 2 paths:
[1]"C:/Users/xxxxxx/Documents/R/win-library/4.1"
[2] "C:/Program Files/R/R-4.1.2/library"
The first path has folders for the old and new versions, and the second path for the newly installed version. So, how can I delete the first path?
Thanks!

You can change the default library folder by setting your R_LIBS_SITE environmental variable in 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.2\\library"

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

I edited Rprofile.site file by adding a function with the targeted path, but I can not save the file in C partition got this message " You do not have permission to open this file. See the owner of the file or an adminstrator to obtain permission".

I tried to edit the access properties from the security tab to "Everyone" but it did not work.
Any recommendations!
Thanks in advance

Okay, I changed the permission criteria and now I could save Rprofile.site file. However, when I ran .libPath(), I still have both paths, I do not know why?
What I added to Rprofile file is an extra function as follows:
.First <- function(){
.libPaths("C:/Program Files/R/R-4.1.2/library")
}

Any help, please?

Have you restarted your R session? Those configurations only take effect on startup

Yes, I restarted R and the laptop as well!

Solved! I am okay now.
Much thanks for the community support!
Eman

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.