This answer is about installing additional R packages within R and RStudio. If you are looking for how to install R and RStudio see Installing RStudio -- is this very different from other packages?
Two Ways to Install R packages
I do not recommend RStudio or R with sudo
privileges. Running a single R command with sudo
like sudo R INSTALL fGarch
should be fine. The two methods described below are other alternatives.
1. R package as Ubuntu software
As you use R, you will need to install other R packages. Sometimes these are available in the repositories. Say the r package you want it fGarch
then the package in the repositories is called r-cran-fGarch
. Open a terminal by pressing Cntrl+Alt+T and enter:
sudo apt install r-cran-fGarch
Installing R packages in this way has two benefits:
- It will keep
fGarch
up-to-date. Whenever fGarch
is updated in R-Cran repository, it will be updated in your computer along with the system update process.
- All users of this computer will be able to use the
fGarch
package within R and RStudio.
However, not every R package has a corresponding precompiled installation deb
package in the Cran repository. fGarch
just happens to to one of them. So, the above method does not work for this package.
2. R Package from inside RStudio
R packages such as fGarch
can be easily installed and updated from inside RStudio. If you do this, you will see the error message and find that RStudio puts the new files (including updates) inside in your home directory /home/<user>/R/site-library/
. This is fine if you are the only user of this computer who use R and RStudio. The "warning" you see will not stop you from using the package fGarch
. However, other users of this computer won't have access to it.
One way to solve this problem and let RStudio install all future additional packages in their proper place is to add yourself to the group staff
. Open a terminal by pressing Cntrl+Alt+T and enter:
sudo adduser <user> staff
Replace <user>
with your username.
After this, you will get the option of installing or updating packages /usr/local/lib/R/site-library/
or in /home/<user>/R/site-library/
. Then you will be able to choose the former as the default install location.
Source: https://stackoverflow.com/questions/5560139/install-r-package-xml-in-debian-ubuntu
Hope this helps