amedicalenthusiast
amedicalenthusiast

Reputation: 282

R cannot install packages - library is not writable and `No such file or directory`

I know that this question is similar to previously asked questions. However, this question differs in some ways.

I have not been able to install any packages into R for some time now. Here's the code:

install.packages("GGally")
Installing package into ‘C:/Users/my_usernames/Documents/R/win-library/4.1’
(as ‘lib’ is unspecified)
Warning in install.packages :
  'lib = "C:/Users/my_username/Documents/R/win-library/4.1"' is not writable

After this, the system keeps prompting me to use a personal library, to which I clicked Yes enter image description here

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.1/GGally_2.1.2.zip'
Content type 'application/zip' length 1637552 bytes (1.6 MB)
downloaded 1.6 MB

Warning in install.packages :
  cannot create dir 'C:\Users\my_username\Documents\R\win-library\4.1\file778128e2f03', reason 'No such file or directory'
Error in install.packages : unable to create temporary directory ‘C:\Users\my_username\Documents\R\win-library\4.1\file778128e2f03’

Some things that I did but didn't work out:

  1. Running RStudio with administrator privilege

  2. Using Tools > Install Packages --> after this, a prompt to create a personal library appears, and if I click Yes, the prompt keeps reappearing without any action

  3. Checking the folder manually, and I found that the path C:\Users\my_username\Documents\R\win-library\4.1\ exists

  4. Using dir.create and .libPaths() as suggested by teichert in a previous thread

    dir.create(Sys.getenv("R_LIBS_USER"), recursive = TRUE)

    .libPaths(Sys.getenv("R_LIBS_USER"))

I also found that some people suggested to configure my R profile using

export R_LIBS_USER=/path/to/your/r-library 

or

sudo usermod -a -G staff your_user_name

However, I didn't use any profile while using R or RStudio, so I'm not sure if I have any username or any RStudio profile. I didn't recently update my R or RStudio application as well. I haven't used R or RStudio in a while, and when I opened them again last week the issue pops up.

Any help will be much appreciated. Thank you very much in advance.

Upvotes: 0

Views: 3701

Answers (4)

Velda
Velda

Reputation: 617

I had the same problem with R 4.1.0, where R uses the Documents folder to store the plugins, i.e. application data. This is obviously wrong, against the MS guidelines and would make OneDrive go crazy, which imho may be why this problem appears. In my case, the problem was installing a new version of htmltools package.

I fixed it with a clean installation of R 4.3.3, which probably fixed this. The steps:

  1. Install a current version of R
  2. Open Start/R [your-version]
  3. Try to install the package: Packages/Install package(s), choose repository and then the package
  4. R would ask you if you wish to use a user library for installation, as Program Files is not writable (without the admin rights) -> yes
  5. R will ask you if you wish to create a library in AppData folder -> yes R asking user to create a personal library
  6. Open RStudio, set [your-version] R version as your default
  7. Use R/RStudio as normally

It should work now. As an alternative, you can follow these steps and you should be able to relocate your plugin library (e.g to %AppData%/R/[your-version]/). I have not tried, cannot confirm.

Upvotes: 0

mustafademir
mustafademir

Reputation: 1

install.packages("GGally")
Installing package into ‘C:/Users/my_usernames/Documents/R/win-library/4.1’
(as ‘lib’ is unspecified)
Warning in install.packages :
  'lib = "C:/Users/my_username/Documents/R/win-library/4.1"' is not writable

Maybe you should change "my_usernames" part. you write your your own name

Upvotes: -2

mustafademir
mustafademir

Reputation: 1

After this, the system keeps prompting me to use a personal library, to which I clicked Yes "try to click no"

Upvotes: -3

mustafademir
mustafademir

Reputation: 1

maybe you need to run Rstudio as "administrator" to be able to install on this folder. so you can fix that problem

Upvotes: -4

Related Questions