Solve Your Install Packages Problem Error in R Studio



Are you a newbie to a programming language? Well, I am, and my goal here is to use it as a tool for my data science projects.

While I am starting my journey in a programming language with R and Python, I face several newbie problems that I need to solve for me to be able to learn correctly. One of my very first problems is the "install packages error" in R Studio. My first attempt using > install.packages ("...") command is to install the "ggplot2" package, and it is, in fact, running smoothly.

However, the next day, when I try to install the "openxlsx" package, I keep getting on the same pop-out messages:

Warning in install.packages:'lib="C:/Users/myaccount/OneDrive/Document/R/win-library/4.1" 'is not writeable.

No matter which procedure I used to install it, whether through command in Console, install packages in Tools tab, or install in Packages tab. It's all the same. Sometimes, when I force R studio to choose an alternate folder to install my packages, it will start installing and downloading them. Like it usually processes the command. But then again, in the end, two different messages appear on my Console saying:

Warning in install.packages: cannot create dir 'C:\Users\myaccount\OneDrive\Document\R\win-library\4.1\file2d9c17c720b3', reason 'No such file or directory'

Error in install.packages: unable to create temporary directory 'C:\Users\myaccount\OneDrive\Document\R\win-library\4.1\file2d9c17c720b3'.



I am frustrated as I need to install openxlsx packages in order to use the library (openxlsx). I tried to ask some of the data scientist community members in Indonesia about this problem, but there was no answer. So, I did my own research, I wandered around tech forums on the internet to find the solutions.

Turned out; there are many people (not that many but yeah, quite many) facing a similar problem as I did. Surprisingly, the solution varies depending on the source of the problem itself. We might be facing the same problem, which is a package install error, but the source of this problem could be different. Different sources of problems require different solutions. From experience, I knew that trying several methods that did not work could be devastating. It is enough to demotivate your further learning goal.

Good for you, my fellow strangers on the internet; I had been tried all the solutions offered and successfully solved the problem. Therefore, based on my own experience and what I learned about other people's experiences, I would like to share the solutions and the source of the problem details with you guys. So that you don't have to be frustrated for a week as I did. LoL.

Principally there are four options out there for you to try. But at first, you have to understand your main problem. Based on the error messages, you might think there is a permission problem that prevents R Studio from accessing your file directory. 


Warning in install.packages: 'lib="C:/Users/myaccount/OneDrive/Document/R/win-library/4.1" 'is not writeable. 


In the error message above, R Studio wants to download and install your packages to a directory in C:/Users/myaccount/OneDrive/Document/R/win-library/4.1, but somehow, R does not has permission to do it.


We often see these issues with someone running R on a network and having a shared network disk that they store things on, but that doesn't seem to be the case here. I am using R on my own, I am not sharing my network, and no parties are involved. If your case is similar to mine, one thing we could try is verifying that this directory hasn't been closed for some reason.


Here's a plenty guide to set permissions for a directory on Windows:

  1. Your first option to try is to check if you may forget to run R as an administrator. It could be the source of the problems. If it is, try to re-run R as administrator. Right-click on the file and choose the Run as administrator option. Nevertheless, you could also use R Studio to fix it. Click Terminal next to Console in R studio. Type "sudo r" to run R as an administrator. Then try again to install your package as usual.
  2. If the first solution made no difference, then try the second option. You could set your file and folder access permission. You as users or R as an application might not have permission to access the folder. It explains why the directory is not writeable. Every file or folder in Windows has its own set of permissions, and Permissions can be broken down into Access Control Lists with users and their corresponding rights. Generally, in Windows, every file or folder gets its permissions from the parent folder. You can access these permissions by right-clicking on a file or folder, choosing Properties, and clicking on the Security tab. To edit permissions for a particular user, click on that user and click the Edit button. For further details about the steps to obtain permission, please check this article below:
  3. How to Set File and Folder Permissions in Windows

  4. Still, get stuck? Here you go, the third option. As you may notice, sometimes, when we need to install or update an application on our computer, we have to turn off our antivirus program first to be able to run it. In my case, the third option is the solution. Perhaps, my problem was a particular case. My Windows Defender Ransomware Protection is on and blocking rsession.exe by default. Authorizing rsession.exe solved the problem. You could check if /path/R.exe is included in Windows Ransomware Protection. Get path from the file.path(R.home("bin"), "R"), or simply just turn off your Windows Defender Ransomware protection in the virus & protection setting. It applies to any other antivirus program out there (Avast, McAfee, etc.). 

  5. Lastly, if you are in a good mood, change your directory / libPaths. Why do you have to be in a good mood? Because it is a little bit need more effort. Please check this link for further details of the step: r - installing package - cannot open file - permission denied


That is all for today; I hope that will solve your problem as I do. As seen above is the proof pic that I solved my problem. LoL. Good luck, pals!


Komentar

Popular Posts

Exploring Japan: My Adventure with the MEXT Research Student Scholarship 2023

Berbagi Pengalaman Tes TOEIC (Test of English for International Communication) ETS