LoginSignup
4
3

More than 5 years have passed since last update.

Rでパッケージがインストールされてないときだけインストールする書き方を教えてください。

Last updated at Posted at 2012-12-26

今はこう書いてますが、他にいい方法ありませんか?

pkg.name <- "animation"

if(length(find.package(pkg.name, quiet=TRUE)) == 0) {
  install.packages(pkg.name)
}

追記:

if(!require("animation")){
  install.packages("animation")
}

これでできる。

pkg.name <- "animation"
if(!require(pkg.name, character.only=TRUE)){
  install.packages(pkg.name)
}

パッケージ名を変数にしたい場合には character.only=TRUE とする。

4
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3