メモ:世界で最もミニマルなRパッケージをつくる

まったく訳に立たない知識。

RのパッケージにはDESCRIPTIONとかNAMESPACEとかRファイルとかいろいろありますが、パッケージとしての体を成す限界はどこなのでしょうか。やってみた感じ、どうやらDESCRIPTIONNAMESPACEさえあればいいようです。

つくってみたパッケージがこれ:

NAMESPACE

最もミニマルなNAMESPACEの中身はこうです:




え、何も見えない? これは心のきれいな人にしか見えないやつで…みたいな展開を想像したかもしれませんが、要は、NAMESPACEは空でも大丈夫です。

空でも大丈夫だけど、ファイルが存在しないとエラーになっちゃうという…。よく分からない。

DESCRIPTION

最もミニマルなNAMESPACEの中身はこうです:

Package: aa
Version: 0.0

これだけですが、細かい縛りがあります。

まず、Package(パッケージ名)は、2文字以上である必要があります。Writing R Extensionsによると、

The mandatory ‘Package’ field gives the name of the package. This should contain only (ASCII) letters, numbers and dot, have at least two characters and start with a letter and not end in a dot.

となっています。これが、

Package: a

だとエラーになります。

Error : Invalid DESCRIPTION file

Malformed package name

See section 'The DESCRIPTION file' in the 'Writing R Extensions'
manual.

あと、Version(バージョン)にも、.-区切りで2つ以上の数字があること、という決まりがあります。

The mandatory ‘Version’ field gives the version of the package. This is a sequence of at least two (and usually three) non-negative integers separated by single ‘.’ or ‘-’ characters. The canonical form is as shown in the example, and a version such as ‘0.01’ or ‘0.01.0’ will be handled as if it were ‘0.1-0’. It is not a decimal number, so for example 0.9 < 0.75 since 9 < 75.

なので、

Version: 0

とかだとエラーになります。

Error : Invalid DESCRIPTION file

Malformed package version.

See section 'The DESCRIPTION file' in the 'Writing R Extensions'
manual.

奥が深いですね。ちなみに、Writing R Extensionsには

The ‘Package’, ‘Version’, ‘License’, ‘Description’, ‘Title’, ‘Author’, and ‘Maintainer’ fields are mandatory

とも書いてあるんだけどなあ…。mandatoryになってるフィールドをなぜ省略できるのか、謎。

最後に

よい子はマネしないでね。