新しいバージョンを確認
「Rのアップデート」を確認すると、新しいバージョン「R4.2.1」が出ていることに気づきました。
今使っているバージョンは「4.1.1」です。
This version of R is 4.1.1
There is a newer version of R on CRAN which is 4.2.0
>
Do you want to visit CRAN now?
2020/4/22 にリースされていました。
これまでバージョンを変えたことがないので、アップデートすることにしました。
(Rの経験が少ない一利用者の試行錯誤として、以下をお読みいただければと思います)
インストール
「Download R for macOS」を選びます。
まずインストーラーをダウンロードして実行しました。
パッケージが?
新しいバージョンに変わっています。
version
_
platform aarch64-apple-darwin20
arch aarch64
os darwin20
system aarch64, darwin20
status
major 4
minor 2.0
year 2022
month 04
day 22
svn rev 82229
language R
version.string R version 4.2.0 (2022-04-22)
nickname Vigorous Calisthenics
ところが、パッケージは引き継がれていませんでした。
以下は「dplyr」の例です。
library(dplyr)
Error in library(dplyr) : there is no package called ‘dplyr’
パッケージをコピー
ネットを検索して、パッケージを「R 4.2.0」のディレクトリにコピーする例を見つけたので、試してみます。
Rが立ち上がらなくなったので、再度「R 4.2.0」をインストールし直しました。
コピーしたライブラリのディレクトリは残ったままです。
先ほどとは異なるエラーが出てしまいました。
library(dplyr)
Error: package or namespace load failed for ‘dplyr’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/rlang/libs/rlang.so':
dlopen(/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/rlang/libs/rlang.so, 0x0006): Library not loaded: /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/lib/libR.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/rlang/libs/rlang.so
Reason: tried: '/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/lib/libR.dylib' (no such file), '/usr/local/lib/libR.dylib' (no such file), '/usr/lib/libR.dylib' (no such file)
一旦「R 4.1.1」に戻すことにしました。
updateR()を使用
次に、ネットで見つけた「installr」パッケージの「updateR」関数を使ってみました。
「R」のアップデートやパッケージの引き継ぎができるようなことを書いてあるサイトも見つけました。
まずは、「R 4.1.1」に戻り、パッケージが使えるのを確認します。
version
_
platform aarch64-apple-darwin20
arch aarch64
os darwin20
system aarch64, darwin20
status
major 4
minor 1.1
year 2021
month 08
day 10
svn rev 80725
language R
version.string R version 4.1.1 (2021-08-10)
nickname Kick Things
library(dplyr)
iris %>% filter(Species == "virginica") %>% head()
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 6.3 3.3 6.0 2.5 virginica
2 5.8 2.7 5.1 1.9 virginica
3 7.1 3.0 5.9 2.1 virginica
4 6.3 2.9 5.6 1.8 virginica
5 6.5 3.0 5.8 2.2 virginica
6 7.6 3.0 6.6 2.1 virginica
「updateR()」を実行しましたが、今まで見たことがないエラーが出ました。
「winDialog」というワードから、何となくこれは使えそうもない予感がしてきました
library(installr)
updateR()
Error in winDialog(type = "ok", message = message_text) :
could not find function "winDialog"
In addition: Warning message:
In get.installed.R.folders() :
Could not find any R installation on your system. (You might have installed your R version on 'c:\R' without sub folders...
Windows用だった
さらに調べてみると、「installr」パッケージはWndows用であることがわかりました。
Using R to Install Stuff on Windows OS (Such As: R, 'Rtools',
'RStudio', 'Git', and More!)
Macでも使えそう
Macで使えるバージョンがないか調べていると、「installrh」の仕様が載っているサイトに
If you are using Mac you can easily upgrade to the latest version of R using Andrea Cirillo’s updateR package. The package is not on CRAN, so you’ll need to run the following code in Rgui:
という記述を見つけました。
(ただ、最終更新が2018年4月)
記載コードを参考に進めてみました。
「updateR」の開発版を「installr」は別にインストールします。
install.packages("devtools")
install_github("AndreaCirilloAC/updateR")
Downloading GitHub repo AndreaCirilloAC/updateR@HEAD
These packages have more recent versions available.
It is recommended to update all of them.
Which would you like to update?
1: All
2: CRAN packages only
3: None
4: stringi (1.7.4 -> 1.7.6) [CRAN]
5: magrittr (2.0.1 -> 2.0.3) [CRAN]
「Installing R-4.2.0...please wait:」というメッセージが出ました。
目的にかなり近づけた気がします。
Reinstall or Copy all packages
パッケージについて、「再インストールするか」「コピーするか」を聞かれました。
「2:コピー」を選んでみました。
library(updateR) #installerは事前にインストールしておく
updateR()
Enter password for user_name
Updated ~/.Rprofile
trying URL 'http://cran.rstudio.com/bin/macosx/base/R-4.2.0.pkg'
Content type 'application/octet-stream' length 93948963 bytes (89.6 MB)
==================================================
downloaded 89.6 MB
Installing R-4.2.0...please wait:
#中略
This is a minor update.
Choose one of the following options to restore your packages:
1. Reinstall all the packages
2. Copy all packages
2
Error in str_replace(l, old_version_path, new_version_path) :
could not find function "str_replace"
「Error in str_replace」とエラーが出ました。
「str_replace」は「stringr」パッケージの関数です。
不思議に思ったのですが、何となく「library(stringr)」を実行後に再度「updateR()」を動かしたところ、先に進めました。
updateR()
This is a minor update.
Choose one of the following options to restore your packages:
1. Reinstall all the packages
2. Copy all packages
2
Copying from old LibPath
/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/
to new LibPath
/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/
...
Added /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library to ~/.Rprofile
Complete.
Everything went smoothly, R was updated to R version 4.2.0 (2022-04-22) -- "Vigorous Calisthenics"
Also the packages installed on your previous version of R were restored
コピーが完了したようです。
またエラー
「R 4.2.0」になっています。
R version 4.2.0 (2022-04-22) -- "Vigorous Calisthenics"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin17.0 (64-bit)
しかし、パッケージは変わらず動きません。
前と同じエラーが出ました。
library(dplyr)
Error: package or namespace load failed for ‘dplyr’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/rlang/libs/rlang.so':
dlopen(/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/rlang/libs/rlang.so, 0x0006): tried: '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/rlang/libs/rlang.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))
「コピー」は、前述のライブラリのコピーと同じことをしただけのようです。
「1:再インストール」も試してみます。
再インストールでも引き継げず
「installr」と「updateR」アンインストールしておきます。
Rを再起動しました。
remove.packages("installr")
remove.packages("updateR")
「updateR」を実行し、「1:再インストール」を選びます。
install.packages("devtools")
devtools::install_github("AndreaCirilloAC/updateR")
library(stringr)
library(installer)
library(updateR)
updateR()
This is a minor update.
Choose one of the following options to restore your packages:
1. Reinstall all the packages
2. Copy all packages
1
list of packages loaded
abind, askpass, assertthat, backports, base64enc, BH, bit, bit64, blob, boot, brew, brio, broom, cachem, callr, cellranger, checkmate, class, classInt, cli, clipr, cluster, #(略)
エラーは出ずに終わったようです。
「‘RMeCab’, ‘updateR’ are not available」というメッセージは出ましたが、パッケージが引き継がれていればリカバリできるので先に進みます。
The downloaded source packages are in
‘/private/var/folders/44/3m206wpj4db2vyqz3bt_ltkm0000gn/T/RtmpqYXvLM/downloaded_packages’
Everything went smoothly, R was updated to R version 4.2.0 (2022-04-22) -- "Vigorous Calisthenics"
Also the packages installed on your previous version of R were restored
Warning message:
packages ‘RMeCab’, ‘updateR’ are not available for this version of R
Versions of these packages for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
結局引き継げず
Rを再起動しました。
残念ながら、パッケージは引き継がれていませんでした。
再インストールはされたのですが、「R 4.1.1」のディレクトリに対して行われたようで、「R 4.2.0」のディレクトリには該当するパッケージは入っていませんでした。
「Mac用updateR」ということでしたが、インストールされた「R 4.2.0」は、arm64版ではなかった動作も見受けられました(これは再確認していないので推測です)。
library(dplyr)
Error in library(dplyr) : there is no package called ‘dplyr’
結局、「R 4.1.1」に戻してRを使い続けることにしました。
R 4.2.0へパッケージを引き継ぎ方法はもう少し探すつもりですが、全パッケージをインストールし直した方が早い気がしてきました。
同じことをしないようにここにメモをしておきましたが、中途半端な結果に終わり大変恐縮です。
了