LoginSignup
10
9

More than 5 years have passed since last update.

パッケージの出所を確認

Last updated at Posted at 2014-12-17

GitHub

最近、パッケージをCRANだけでなくGitHubから直接インストールしているユーザーも多いかと思います。が、そうすると、いま使っているパッケージがどっちからインストールしたのか忘れてしまうことがあります。バージョンとかを確認すれば良いだけなんですが、とりあえずRのコンソールでレポジトリの出所を調べるにはpackageDescription()コマンドを使います。

> packageDescription("magrittr")
Package: magrittr
Type: Package
Title: A Forward-Pipe Operator for R
Version: 1.5
Author: Stefan Milton Bache <stefan@stefanbache.dk> and Hadley Wickham
        <h.wickham@gmail.com>
Maintainer: Stefan Milton Bache <stefan@stefanbache.dk>
Description: Provides a mechanism for chaining commands with a new
        forward-pipe operator, %>%. This operator will forward a value,
        or the result of an expression, into the next function
        call/expression. There is flexible support for the type of
        right-hand side expressions. For more information, see package
        vignette.  To quote Rene Magritte, "Ceci n'est pas un pipe."
Suggests: testthat, knitr
VignetteBuilder: knitr
License: MIT + file LICENSE
ByteCompile: Yes
RemoteType: github
RemoteHost: api.github.com
RemoteRepo: magrittr
RemoteUsername: smbache
RemoteRef: master
RemoteSha: 5d1e52654f9c94796d98f88a968aab434a665aa0
GithubRepo: magrittr
GithubUsername: smbache
GithubRef: master
GithubSHA1: 5d1e52654f9c94796d98f88a968aab434a665aa0
Built: R 3.1.2; ; 2014-12-05 09:29:19 UTC; unix

出力の最後にGitで始まる要素が並んでおり、この環境では、magrittrパッケージがgithubからインストールされていることが分ります。

CRAN

ちなみにCRANからインストールしたパッケージの場合には次のような出力になります。

> packageDescription("pipeR")
Package: pipeR
Type: Package
Title: Pipe operator and function
Version: 0.5
Author: Kun Ren <ken@renkun.me>
Maintainer: Kun Ren <ken@renkun.me>
Description: Provides Pipe operator and function based on syntax which
        support to pipe value to first-argument of a function, to dot
        in expression, by formula as lambda expression, for
        side-effect, and with assignment.  The set of syntax is
        designed to make the pipeline highly readable.
Depends: R (>= 2.15)
Date: 2014-09-30
Suggests: testthat
License: MIT + file LICENSE
URL: http://renkun.me/pipeR, https://github.com/renkun-ken/pipeR,
        http://renkun.me/pipeR-tutorial
BugReports: https://github.com/renkun-ken/pipeR/issues
ByteCompile: TRUE
Packaged: 2014-09-30 12:21:02 UTC; Ken
NeedsCompilation: no
Repository: CRAN
Date/Publication: 2014-09-30 17:59:43
Built: R 3.1.2; ; 2014-12-05 09:35:12 UTC; unix

Repository という要素に "CRAN" という値が記録されています。他にありそうな値は "R-Forge" です。

R-Forge

そうです、あるんです。Rには伝統的に R-Forge という開発サイトが。最近あまり注目されなくなりましたが、使ってみましょう。

 >  install.packages( "maxLik", repos="http://R-Forge.R-project.org" )
 Installing package into ‘/home/釘宮/R/x86_64-unknown-linux-gnu-library/3.1’
 (as ‘lib’ is unspecified)
  URL 'http://R-Forge.R-project.org/src/contrib/maxLik_1.2-2.tar.gz' を試しています 
 中略
 > packageDescription("maxLik")$Repository
 [1] "R-Forge"

今も、ここで盛んに開発されているパッケージもありますので、一度は覗いてみましょう。

ところでGitHubからインストールしたパッケージの場合は、なぜかRepository要素がなくて、別に追加された RemoteTypeという項目に github と登録されます。できれば統一して欲しいもんです。

アーカイブから

さてパッケージって、いつの間にか CRAN から消えていることがあります。
よく目にするのが、R本体のメジャー・バージョンアップにパッケージ更新を間に合せることができないというケースです。CRANのパッケージ・ポリシーが厳しくなって、もう面倒になったってな話も聞きます。このくそなポリシーについては各所で頻繁に議論になっていますが、ここでは無視しましょう。

さまざまな理由から消えてしまったパッケージですが、実はCRANのアーカイブには残っています。ですのでアーカイブのURLを指定すれば、あっさりインストールできることもあります。

たとえばUSPSというパッケージがあったのですが、2014年12月現在CRANからは消えています。

USPS.png

アーカイブのリンクが生きているようなので、クリックするとこんな感じでした。

USPS2.png

この中の最新版のURLをコピーして、インストールしてみます。

 > install.packages ("http://cran.r-project.org/src/contrib/Archive/USPS/USPS_1.2-2.tar.gz", repos = NULL )
 Installing package into ‘/home/釘宮/R/x86_64-unknown-linux-gnu-library/3.1’
 (as ‘lib’ is unspecified)
  URL 'http://cran.r-project.org/src/contrib/Archive/USPS/USPS_1.2-2.tar.gz' を試しています 
 Content type 'application/x-gzip' length 434206 bytes (424 Kb)
  開かれた URL 
 ==================================================
 downloaded 424 Kb

 * installing *source* package ‘USPS’ ...
 **  パッケージ ‘USPS’ の解凍および MD5 サムの検証に成功しました 
 ** R
 ** data
 ** demo
 ** inst
 ** preparing package for lazy loading
 ** help
*** installing help indices
 ** building package indices
 ** testing if installed package can be loaded
 * DONE (USPS)
 > library(USPS)
 要求されたパッケージ cluster をロード中です 
 要求されたパッケージ lattice をロード中です 
 要求されたパッケージ gss をロード中です

運良く、インストールでき、読み込みにも問題がありませんでした。

オレオレ鯖

まあ、皆さん、パッケージ登録はCRANだけが選択肢ではないです。プライベートなサーバーに設置することもできます。要はサーバーにRというフォルダを作成し、以下のように階層化すれば良いだけです。

www/R/src/cotrib/Hoge_0.02.tar.gz
www/R/bin/windows/contrib/3.1/Hoge_0.02.zip
www/R/bin/macosx/contrib/3.1/Hoge_0.02.tgz
www/R/bin/macosx/mavericks/contrib/3.1/Hoge_0.02.tgz

最下層のフォルダにバイナリファイルなりソースファイルなりを置きます。その階層に PACKAGES という名前のファイルを用意し、以下のように書いておきます。

Package: Hoge
Version: 0.02
Depends: R (>= 3.1.2)

Package: Hoge
Version: 0.01
Depends: R (>= 3.1.0)

あと、すべてのフォルダにダミー(空)の index.html を用意しておくと、妙な警告などが表示されなくなります。

インストールは以下のようにします。

install.packages("Hoge", repos = "http://kugimiya3.daisuki.com/R")

身内とか小さなグループでパッケージをやりとりするのに便利だと思います。

10
9
0

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
10
9