最も手抜きのパッケージ作成

  • 昨日の記事に書いたように、Rstudioの機能を使って、パッケージを作ってみた(細かい操作手順は昨日の記事で)
  • 日本語、禁なので、「私が便利に使うためのパッケージ化」を目指すなら、
    • 「極力、手間を削りたい」
    • 「必要な情報は、別途、日本語で文書に書いておく方がよい」
  • こんなケースを想定して、「ここまで手を抜いても大丈夫」の確認
  • 手順
    • (1) 日本語を使っていない、関数ばかりのテキストファイルを用意(たとえば以下のようなもの)。ファイル名は、たとえば"ry.R"
test1 <- function(x){
	plot(x)
}
test2 <- function(n){
	x <- runif(n)
	test1(x)
}
    • (2)Rstudioを立ち上げてパッケージ用プロジェクトを作る
      • ツールバー→ File → New Project → New Directory → R package
      • パッケージ名(仮に"ry")の指定、"ry.R"をAdd、パッケージ作成ディレクトリを適当に作成して指定
    • (3)文書編集(manフォルダのファイルだけいじる、後は何も触らない)。本当に以下だけ
      • (a)ry-package.Rd
        • \examplesの中身だけ削除
      • (b)関数の"xx.Rd"は、以下するだけ
        • ケルトンとして書いてある"title{}","description{}","examples{}"を削除
        • 代わりに、無意味だけれど、ちゃんとパッケージ化処理が受け取ってくれるように、"文字列"を入れておく。examplesはコメントアウトした行を入れておく。この9行をすべての関数用".Rd"ファイルに使い回す。
        • ただし、「削除」と指定した以外の項目は、関数名・関数の内容に依存した内容なので、削除しない。何か書きたければ書くのは(非日本語で)なら可
\title{
(^_^)
}
\description{
(^_^)
}
\examples{
# (^_^)	
}
    • (3) ビルドして、チェックして、配布用を作る
      • Build & Reloadを実行、ついでCheckを実行、ついで、More のBuild source package とBuild Binary packageを実行
    • (4) 使う
      • 自身のRから、"ローカルにあるzipファイルからのパッケージのインストール…"で作成したzipファイルを指定する
  • 終わり
  • サンプルファイル
    • 編集したファイル
      • ry-package.Rd(末尾のexamplesだけいじった)
\name{ry-package}
\alias{ry-package}
\alias{ry}
\docType{package}
\title{
What the package does (short line)
~~ package title ~~
}
\description{
More about what it does (maybe more than one line)
~~ A concise (1-5 lines) description of the package ~~
}
\details{
\tabular{ll}{
Package: \tab ry\cr
Type: \tab Package\cr
Version: \tab 1.0\cr
Date: \tab 2014-04-30\cr
License: \tab What license is it under?\cr
}
~~ An overview of how to use the package, ~~
~~ including the most important functions ~~
}
\author{
Who wrote it

Maintainer: Who to complain to <yourfault@somewhere.net>
~~ The author and/or maintainer of the package ~~
}
\references{
~~ Literature or other references for background information ~~
}
~~ Optionally other standard keywords, one ~~
~~ per line, from file KEYWORDS in the R ~~
~~ documentation directory ~~
\keyword{ package }
\seealso{
~~ Optional links to other man pages, e.g. ~~
~~ \code{\link[<pkg>:<pkg>-package]{<pkg>}} ~~
}
\examples{

}
      • test1.Rdファイル
\name{test1}
\alias{test1}
%- Also NEED an '\alias' for EACH other topic documented here.
\title{
(^_^)
}
\description{
(^_^)
}
\examples{
# (^_^)  
}
\usage{
test1(x)
}
%- maybe also 'usage' for other objects documented here.
\arguments{
  \item{x}{
%%     ~~Describe \code{x} here~~
}
}
\details{
%%  ~~ If necessary, more details than the description above ~~
}
\value{
%%  ~Describe the value returned
%%  If it is a LIST, use
%%  \item{comp1 }{Description of 'comp1'}
%%  \item{comp2 }{Description of 'comp2'}
%% ...
}
\references{
%% ~put references to the literature/web site here ~
}
\author{
%%  ~~who you are~~
}
\note{
%%  ~~further notes~~
}

%% ~Make other sections like Warning with \section{Warning }{....} ~

\seealso{
%% ~~objects to See Also as \code{\link{help}}, ~~~
}
\examples{
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.


% Add one or more standard keywords, see file 'KEYWORDS' in the
% R documentation directory.
\keyword{ ~kwd1 }
\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line
      • test2.Rdファイル
\name{test2}
\alias{test2}
%- Also NEED an '\alias' for EACH other topic documented here.
\title{
(^_^)
}
\description{
(^_^)
}
\examples{
# (^_^)  
}
\usage{
test2(n)
}
%- maybe also 'usage' for other objects documented here.
\arguments{
  \item{n}{
%%     ~~Describe \code{n} here~~
}
}
\details{
%%  ~~ If necessary, more details than the description above ~~
}
\value{
%%  ~Describe the value returned
%%  If it is a LIST, use
%%  \item{comp1 }{Description of 'comp1'}
%%  \item{comp2 }{Description of 'comp2'}
%% ...
}
\references{
%% ~put references to the literature/web site here ~
}
\author{
%%  ~~who you are~~
}
\note{
%%  ~~further notes~~
}

%% ~Make other sections like Warning with \section{Warning }{....} ~

\seealso{
%% ~~objects to See Also as \code{\link{help}}, ~~~
}

% Add one or more standard keywords, see file 'KEYWORDS' in the
% R documentation directory.
\keyword{ ~kwd1 }
\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line
      • いじっていないDESCRIPTIONファイルは
Package: ry
Type: Package
Title: What the package does (short line)
Version: 1.0
Date: 2014-04-30
Author: Who wrote it
Maintainer: Who to complain to <yourfault@somewhere.net>
Description: More about what it does (maybe more than one line)
License: What license is it under?
    • これで現れる、ヘルプ記事は
library(ry)
help(ry)

    • Indexにリンクで飛べば

    • test1()関数のヘルプに飛べば