8

I was using my own laptop to install R and I found that it only has one library. Evne though this library is still read only, everytime when I use Rstudio: install.packages("abc"), I can see that the new packages are stored automatically into that read only library folder.

In my office's desktop, I "believe" I also have administrator role, as I can install and remove anything (by far). I download the latest version of R and I right click the R-3.4.1-win.exe, there is an item "run as administrator", then it is installed in my desktop. However, when I use R studio to install new packages as in my laptop, it always automatically create a personal folder to store the new packages. I don't know why. Is that a way to only have one folder for library? I also tried on the desktop in the plain R mode (without using Rstudio). When I want to install new packages, it always says

Warning in install.packages("devtools") :
  'lib = "C:/Program Files/R/R-3.4.1/library"' is not writable

And there is a window pops up to ask me "would you like to create a personal folder?" And if I say no, then

Error in install.packages("devtools") : unable to install packages.

Is there a ways to solve this problem? To just maintain one folder for library

kim kevin
  • 175
  • 1
  • 2
  • 9
  • Install r in a directory you have write access to, e.g. `C:/R`. Then you'll have no trouble installing packages. Alternatively, set up an alternative location for R library folder. – mikeck Jul 26 '17 at 03:28
  • This may start a debate, but with few exceptions (e.g., `packrat`) you should not be installing new libraries into the system library. I don't want to grossly categorize users, but it is a common non-unix-y thing to think along the lines of "one user having total control over all things on a computer"; a common unix-y way to think about things is to have the global default "sane" (meaning a reasonable default), and have each user able to "append" or add to what is available. E.g., if user "b" on your system wants to install an older version of a package, why should you be forced to use it? – r2evans Jul 26 '17 at 04:13
  • @mikeck thanks! Yes, now it indeed just has one library folder as in my own laptop – kim kevin Jul 26 '17 at 04:29
  • @r2evans: I can see your point, but my life is much more simple on a NIX device if all my packages are in the system directory. The default was to have both a system and a user /library/ but I found that duplication started piling up and I sometimes didn't get the most current version loaded. – IRTFM Jul 26 '17 at 04:59

3 Answers3

12

What version of Windows are you using? You should be able to right-click on the Rstudio.exe icon, click Properties, and select an option to always run Rstudio as administrator. Be sure you use that same icon whenever you want to open Rstudio.

Jay
  • 442
  • 1
  • 5
  • 13
  • This seems more like a comment than an answer. – r2evans Jul 26 '17 at 04:03
  • 1
    Thanks for the feedback @r2evans2 . I don't have enough reputation to post comments on questions, because I'm relatively new here... Does that mean I should just not respond to the question at all? (Honest question.) – Jay Jul 26 '17 at 04:06
  • 2
    Great question, I had to look it up. Apparently, [it's been asked before](https://meta.stackexchange.com/a/214174/300391), with a "fair" answer. I don't have a good answer, sorry. I see that actually it *is* a valid answer, though one with which I disagree (and dismissed prematurely) and feeling as I do, had not considered it enough of an answer without taking pause. Thanks for encouraging a moment of retrospection ... – r2evans Jul 26 '17 at 04:10
  • Guess who now has enough reputation to post comments, thanks to answering this question? :p – Jay Jul 26 '17 at 04:34
  • This was really not either an "R" question or an RStudio question, but rather a Windows question. – IRTFM Jul 26 '17 at 04:55
  • @42- I apologize for my ignorance of operating system. During my work, I found that writting code to do some analysis is OK, but the really hard thing, which often drives me crazy is to config the environment and path, stuff like that, so as to install a package correctly. Do you have some suggestions for some courses or textbooks that can help me understanding what exactly is going on when we try to install packages and change registry? – kim kevin Jul 26 '17 at 13:18
  • 3
    I would just like to say that you shouldn't feel the need to apologize about this. The problem you posted is common, and I answered it because it is something I've had to deal with a couple of times myself. Don't let people on stackoverflow make you feel guilty about asking honest questions. – Jay Jul 26 '17 at 15:17
2

Incase of Mac, go to Applications, then right click on RStudio and

  1. Select "Show Package Contents"
  2. Go to Contents/MacOS
  3. Now open terminal(in bash mode). Type sudo and drag the RStudio.exec into terminal and press on ENTER

Now RStudio will have admin access!

0

For completeness, I think there should be an Ubuntu answer to go along with the Microsoft and Apple answers. (Note:I'm using 18.06, and not 20.x.)

What doesn't work:
On my Ubuntu/Linux system, when Rstudio is installed the call start RStudio from a terminal looks something like the following:

(base) username@sysname:~$ rstudio 

It starts, but has the permissions of the user, and can have access errors.

What gives admin power:
To give it better permissions, you can use sudo.

(base) username@sysname:~$ sudo rstudio 
[sudo] password for username: <enter password here>

It starts in a different user location, but has more power. After it is installed you can run it the regular way and the packages are still installed.

Extra credit:
Here are some (currently) relevant links for RStudio on Ubuntu:

EngrStudent
  • 1,924
  • 31
  • 46
  • 1
    I do not think the Anaconda bit is pertinent to the question (that's just how you run Rstudio through terminal under any *nix environment). Also, it might be worth specifying that `sudo rstudio` isn't just for Ubuntu, but for virtually anything using `sudo` (most commonly, Linux). Finally, I think it's misleading to say that it allows "more power", it just grants admin access to specific files/folders (which is what OP needed 4 years ago). – Giulio Centorame Nov 26 '21 at 15:39