※最新バージョンのWindowsやRの場合は問題なくインストールできるようです。
環境
OS: Windows 10 Pro (10.0.19043)
R: 4.1.2 (2021-11-01)
RStudio: 2021.09.0 Build351
エラー内容
> install.packages("sets")
WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:
https://cran.rstudio.com/bin/windows/Rtools/
パッケージを ‘C:/yourdir/R/win-library/4.1’ 中にインストールします
(‘lib’ が指定されていないため)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.1/sets_1.0-21.zip'
Content type 'application/zip' length 656297 bytes (640 KB)
downloaded 640 KB
package ‘sets’ successfully unpacked and MD5 sums checked
Error in install.packages : ERROR: failed to lock directory ‘C:\yourdir\R\win-library\4.1’ for modifying
Try removing ‘C:\yourdir\R\win-library\4.1/00LOCK’
エラーの指示通り「00LOCK」を削除しても解決しなかった(パッケージをインストールしようとすると自動生成されてしまう)。
解決方法
調べてみるとStack Overflowにも同様の質問があり、回答に従ってinstall.packages()の前に下記コマンドを実行することでインストールできた。
options("install.lock"=FALSE)