I cannot install the packages

I was trying to install some packages, such as, caret, ROCR, ggplot2, etc. They are not in library, so I wrote the code: install.packages(). Each time I select a package, it is unpacked, but I am unable to install, and error message comes, which is given below. Could anyone plz guide me how to proceed further, as I have another class tomorrow, and if I am unable to install all packages, I cannot do hands on practice in the class.

package ‘proxy’ successfully unpacked and MD5 sums checked
Error in install.packages : ERROR: failed to lock directory ‘C:\Users\Somaria Azam\OneDrive\Pictures\Documents\R\win-library\4.0’ for modifying
Try removing ‘C:\Users\Somaria Azam\OneDrive\Pictures\Documents\R\win-library\4.0/00LOCK’

R has known issues with package libraries located at cloud synced folders (OneDrive in your case). I would recommend setting your package library in a non synced folder.

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

2 Likes

Hi @andresrcs , I followed your advice, but no luck, still the same error. Though I was able to create variable R_LIBS_SITE successfully. Is there any way, I could remove or detach the link of RStudio with my OneDrive, or any cloud. I think I first need to detach the link of R library with OneDrive, then set-up a library in a Renviron file. I need more advice on delinking!

RStudio is not linked to OneDrive, your Windows home folder is configured to be synced with OneDrive and the default R package library location is set to be your home folder.

If your package library location hasn't changed then you haven't set the environment variable successfully as you think.

Hi, I see the variable in Environment window, but now my RStudio is responding to all the codes, invalid entry. My class will start in 45 mins, and another problem is added.

i thought today, i would be able to install the packages and will run the code with the class side by side. But here, even the previous codes stopped working!

not responding to all the codes

You are not supposed to create the variable into your R session, that is supposed to be a system environment variable defined at startup. Read the instructions on the blog more carefully.

Hi @andresrcs, oculd u explain me further about this paragraph. "The way to change a package library location is to manually set it on a startup file i.e. Rprofile.site and Renviron.site files for R-version level (located at R_HOME/etc/ ) or .Rprofile and .Renviron files, for user-level (located at your HOME folder) or project-level (located at the current working directory)."

  1. How to find start up file-'Rprofile site' and 'Renviron'
    Home folder
    Please guide me further about these locations.
    Thanks. I have a user-level account I guess, would u guide me further, how can I check which account I have. I am learning Data Science through Intellipaat.com. Though lectures and material is good, but their support team is not of much help.

I think that you need to delete the 00LOCK file.

Hi @jrkrideau, I tried deleting, but no luck. Yesterday night i uninstalled both R and RStudio. Now I need my friends' guidance and school's support. Just figuring which privilege I should proceed with, administrator or user?

Did you euven find the 00LOCK file? It is not the original problem but it will block a new try at an installation.

Admin almost certainly.

They do not necessarily exist but you can create them, they are basically text files.

The HOME folder location depends on your specific operating system configuration, in your case your the HOME folder is located at C:\Users\Somaria Azam\OneDrive

By "user-level" the blog is referring to the scope on which the startup file is applied, not to any account type.

To make things easier for you I'm going to summarize, just open any text editor and type the line R_LIBS_SITE="C:\\Program Files\\R\\R-4.1.2\\library" on it (I'm assuming you are using the latest R version, if not, change the line accordingly with your R version) then save the file with the name Renviron.site (the .site extension is important, make sure to use it) in this folder C:/Program Files/R/R-4.1.2/etc/.
This would set your package library to the default system level location the next time you open an R session, just remember to execute R as "Administrator" to be able to install packages on that location.

1 Like

Thank u so much @andresrcs, I understood it well. As I have uninstalled my R and RStudio yesterday night, and next thing is to re-install those. This time should I install as administrator or user. I heard that administrator account has different set of issues. Now if I reinstall as user, your suggestion that at starting of each R session, I should start as administrator. Plz guide me further, how to start R session as an administrator? Thanking in anticipation! You had been very helpful for me.

You make right click on the RStudio icon and choose the "Run as administrator" option.

This sort of thing, along with what type of user you should be using on Windows is not actually related to R or RStudio but to the general use of a Windows PC so which particular practice to choose falls outside of this forums scope.

Thanks a lot @andresrcs. I followed your directions carefully, and I am able to download the packages successfully. You will be remembered by me a great help in my Data Science journey.

I have this problem as well (WINDOWS ugh) and in my case it seems my documents folder has the R library and I cannot write to it. Here is one approach - First run .libPaths() to find the default directory. Then .libPath("new directory") with a new path. This will I think just be temporary so may not be the best approach. A bad workaround is to create this new directory, install the packages you want to that directory then copy these to the default directory that Rstudio is using. Ugly but it has worked for me before I found the better way.
A better approach was given a while ago and involves adding R_LIBS_USER to your list of environmental variables.

Thanks @Asmith for adding your valuable advise

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.