0

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.

  • Can you manually create a file in the `C:\Users\my_username\Documents\R\win-library\4.1` folder? Just save like a random text file there. It seems very odd that you would not have write permissions to anything in your own Documents folder. Is this a work computer where things are locked down? If you find that folder in the Windows Explorer and right click on it and look at Properties...Security, what do you see? (perhaps add a screen shot to your post). – MrFlick Aug 04 '22 at 13:14
  • @MrFlick Yes I can, I also checked for write permission using `file.access()` and the test shows that the folder is writable. No it's my personal computer so things shouldn't be locked down. The security properties also shows that I have access to the folders and subfolders (see screenshot above) – amedicalenthusiast Aug 04 '22 at 15:06
  • 1
    Well, the screen shot shows the permissions for SYSTEM and not your actual user account. You need to click on your name to see your permissions. So what if we write a test file. Do these lines run without error? `testpath <- file.path(.libPaths()[1], "test.txt"); writeLines("hello", con=testpath); unlink(testpath)` Make sure you are NOT running Rstudio as administrator. That's just not a good idea. – MrFlick Aug 04 '22 at 15:10
  • Sorry I forgot to change the user in the screenshot, but the permissions are same when I click on my user account. Hmm it's true that I cannot write a test file in the folder, although I can create the file manually in Windows Explorer. Any ideas why do this happen? `> testpath <- file.path("C:/Users/Gilbert Lazarus/Documents", "test.txt") > writeLines("hello", con=testpath) Error in file(con, "w") : cannot open the connection In addition: Warning message: In file(con, "w") : cannot open file 'C:/Users/Gilbert Lazarus/Documents/test.txt': No such file or directory ` – amedicalenthusiast Aug 04 '22 at 15:39
  • 1
    Have you tried restarting Rstudio? And maybe your computer? These permissions problems are very odd. They don't appear to be R specific. If you can't programmatically write files to these locations, something odd is going on. How exactly are you running RStudio? – MrFlick Aug 04 '22 at 15:52
  • Restarting RStudio or my computer doesn't solve the problem. I execute RStudio through my desktop, the usual way that I've been doing for the past few years... I've considered reinstalling RStudio, but I think it may be one of the last resorts as I may lose my projects – amedicalenthusiast Aug 04 '22 at 15:58
  • Reinstalling shouldn’t be necessary and it doesn’t sound like it would help in this case. But even if you do reinstall, you shouldn’t lose any projects. – MrFlick Aug 04 '22 at 17:05
  • @MrFlick I see, do you perhaps have any idea on what could be done? Thank you very much for the help – amedicalenthusiast Aug 04 '22 at 17:12
  • 1
    It's so hard to guess what's going on without a reproducible example we can play with. Does the same thing happen if you use R directory rather than RStudio? Sometimes it's the case that a space in a username can cause a problem, but I didn't think that was true in the newest versions of R. You could try changing the location of your library to something outside of your user directory. Like `.libPaths("C:/R/win-library/4.1"). – MrFlick Aug 04 '22 at 17:19
  • @MrFlick Update: When I try to use RGui instead of RStudio, I can create a personal library when the prompt appears. The downloaded packages are placed in a Temp folder `C:\Users\my_username\AppData\Local\Temp\Rtmp2XnIZt\downloaded_packages`. However, since it is not the folder for R packages, I need to manually extract the packages to the folder, which succeeded. This is quite painful especially when I need to install multiple packages, but may do the trick for now... – amedicalenthusiast Aug 04 '22 at 18:01
  • So for now, I can install packages into R by: (1) install the package using R GUI, (2) locate the downloaded package in the Temp folder, and (3) extract the package to R packages folder. Quite annoying, but I think this will do until I can install packages directly in RStudio again – amedicalenthusiast Aug 04 '22 at 18:03
  • 1
    They should be moved to a more permanent location after the temp file. If you run `installed.packages()[, c("Package", "LibPath")]` in RGui you should be able to check that they are no longer in the Temp folder. You shouldn't have to manually move them. As of R 4.2, Windows packages are installed to your AppData folder rather than Documents. But you seem to be on R 4.1 so they should still be moved to your user directory at least. What version of Windows are you using? – MrFlick Aug 04 '22 at 18:11
  • 1
    @MrFlick Thanks for mentioning this! Updating my R version to 4.2 solved the problem. I can now install the packages in RStudio again. Thanks! #p.s.: I'm using Windows 10 Home – amedicalenthusiast Aug 05 '22 at 01:54
  • @MrFlick or amedicalenthusiast, please make an answer from your solution. – fineliner Jun 20 '23 at 08:14

3 Answers3

0
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

Phil
  • 7,287
  • 3
  • 36
  • 66
-3

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

  • Please see the `Some things that I did but didn't work out:` section. I tried running it with administrator privilege but the problem persists – amedicalenthusiast Aug 04 '22 at 13:01
  • Running as administrator would generally be a bad idea. There's no reason not to use a personal library in the users home directory. Running as administrator would likely cause more problems later down the line. – MrFlick Aug 04 '22 at 13:17
-3

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

  • not helping, it just shows error message `Error in install.packages : unable to install packages` – amedicalenthusiast Aug 04 '22 at 13:11
  • Why would you suggest clicking no? The standard way to install packages is to use a personal library. This doesn't really seem to address the real problem of why the user is not able to write to a personal library. – MrFlick Aug 04 '22 at 13:18