LoginSignup
6
3

More than 5 years have passed since last update.

RstudioでRパッケージを作ってみる 2 ~マニュアル作成~

Last updated at Posted at 2016-01-14

目次

  1. RstudioでRパッケージを作ってみる 1 ~自作関数を実行~ - Qiita
  2. RstudioでRパッケージを作ってみる 2 ~マニュアル作成~ - Qiita
  3. RstudioでRパッケージを作ってみる 3 ~パッケージ配布~ - Qiita

はじめに

前回は自作関数を実行してみました。今回はパッケージのマニュアルを作成してみましょう。

パッケージのマニュアルって何でしょうか?
これです(左下)。
英語ではPackage Documentationと言います。

6.png

マニュアルは(ホームディレクトリ)/HelloWorld/man以下に保存されている拡張子Rdのファイルです。

マニュアルを新しく作成してみましょう。RstudioのFile > New File > R Documentationを選択します。

7.png

すると、Rdファイルが新しく作成されます。ここで、新しく作成したファイルを既存のRdファイルと置き換えておきましょう。保存ボタンを押すとmanフォルダが開かれるので、そこのHelloWorld.Rdファイルに上書きしておきます。

8.png

RdファイルはLaTeXに似た構文で記述することが出来ます。
主要な項目を説明しておきますと、以下です。

項目名 説明
name 関数の名前
title 表題
description 関数の説明文
examples 使用例

さて、Rdファイルに適当に記入していきましょう。

\name{hello}
\alias{HelloWorld}
%- Also NEED an '\alias' for EACH other topic documented here.
\title{
%%  ~~function to do ... ~~
hello
}
\description{
%%  ~~ A concise (1-5 lines) description of what the function does. ~~
It prints "Hello world!" ten times. That's all.
}
\usage{
hello()
}
%- maybe also 'usage' for other objects documented here.
\arguments{
  \item{No argument}{
%%     ~~Describe \code{x} here~~
No argument for this function.
}
}
\details{
%%  ~~ If necessary, more details than the description above ~~
Again, it prints "Hello world!" ten times. That's all.
}
\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 ~
[1] www.dummyurl.com
}
\author{
%%  ~~who you are~~
John Doe
}
\note{
%%  ~~further notes~~
This is the note.
}

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

\seealso{
%% ~~objects to See Also as \code{\link{help}}, ~~~
}
\examples{
# prints "Hello world" ten times
hello()
% Add one or more standard keywords, see file 'KEYWORDS' in the
% R documentation directory.
\keyword{ keyword1 }
\keyword{ keyword2 }
\keyword{ keyword3 }
}

これでPreviewボタンを押すと、以下の様に出力されます。

10.png

いかがでしたでしょうか?次回は自作パッケージの公開をしてみます。

6
3
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
6
3