问题
While trying to install a package inside RStudio
on macOS Catalatina,
it fails with a Permission Denied
error:
> install.packages("mlbench")
trying URL 'https://cran.rstudio.com/src/contrib/mlbench_2.1-1.tar.gz'
Content type 'application/x-gzip' length 920768 bytes (899 KB)
==================================================
downloaded 899 KB
* installing *source* package ‘mlbench’ ...
** package ‘mlbench’ successfully unpacked and MD5 sums checked
mv: rename /usr/local/Cellar/r/3.6.1_1/lib/R/library/mlbench to /usr/local/Cellar/r/3.6.1_1/lib/R/library/00LOCK-mlbench/mlbench: Permission denied
ERROR: cannot remove earlier installation, is it in use?
* removing ‘/usr/local/Cellar/r/3.6.1_1/lib/R/library/mlbench’
Warning in install.packages :
installation of package ‘mlbench’ had non-zero exit status
The downloaded source packages are in
‘/private/var/folders/bc/wsz930gj3gn5zgq4hbm6jkfr0000gn/T/RtmpdvQLox/downloaded_packages’
Updating HTML index of packages in '.Library'
Warning in install.packages :
cannot create file '/usr/local/Cellar/r/3.6.1_1/lib/R/doc/html/packages.html', reason 'Permission denied'
Warning in install.packages :
cannot update HTML package index
回答1:
As stated here by RStudio Support:
Are you able to install packages in R?
If you're having issues, we recommend trying to install packages in R (outside of RStudio) and see if you're able to do that. If not, please check the possible solutions below.
Therefore, one needs to:
- switch to
Terminal.app
, - however, R console must be started with the sudo privileges(otherwise, it will yet again fail with a perission denied error):
sudo R
, - and then install whatever package is necessary:
install.packages("mlbench")
.
来源:https://stackoverflow.com/questions/58727775/installing-a-package-inside-rstudio-fails-on-macos-catalina