LoginSignup
9
5

More than 5 years have passed since last update.

RstudioでRパッケージを作ってみる 3 ~パッケージ配布~

Last updated at Posted at 2016-01-15

目次

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

はじめに

前回まではRパッケージの自作関数とマニュアルを作成しました。
今回はそれを世の中に公開してみましょう。

流れとしては、

  1. GitHubにソースコードをpush
  2. Rstudioで、devtoolsパッケージのinstall_githubメソッドを使い自作パッケージをインストール
  3. requireメソッドで自作パッケージを読み込み

となります。

1. GitHubにソースコードをpush

  1. gitをあらかじめインストールしておきます。
  2. あらかじめGitHubのアカウントを作成しておきます。
  3. GitHubで新しいレポジトリを作成します。名前はhelloworld10timesとします。 11.png
    1. +ボタンを押します。
    2. New repositoryを押します。
    3. 新規作成画面が開くので、Repository nameにhelloworld10timesと記入します。
    4. Create repositoryを押します。
  4. 新しく作成したレポジトリに移動します。
  5. レポジトリのurlを以下の手順で控えておきます。 12.png
    1. HTTPSを押します。
    2. Copy to clipboardを押し、urlをクリップボードに控えておきます。
  6. (ホームディレクトリ)/Helloworld/でGit bashを開きます。
  7. 以下のコマンドをbashで入力します。
git init 
git add .
git commit -m "first commit"
git remote add origin (さっき控えたレポジトリのurl)
git push -u origin master

レポジトリのページに移動し、ファイルがpushされているのが確認できたら成功です。

2. Rstudioで、devtoolsパッケージのinstall_githubメソッドを使い自作パッケージをインストール

Rstudioに戻りましょう。devtoolsというGitHubから直接パッケージをインストールできる超絶便利ツールを使って、自作パッケージを入れていきます。

install.packages("devtools")
require(devtools)
install_github("(GitHubのユーザー名)/helloworld10times")

私のGitHubアカウントで試したい場合は、以下を入力してください。

install.packages("devtools")
require(devtools)
install_github("Dixhom/helloworld10times")

3. requireメソッドで自作パッケージを読み込み

> require(HelloWorld)
> hello()
[1] "Hello, world!"
[1] "Hello, world!"
[1] "Hello, world!"
[1] "Hello, world!"
[1] "Hello, world!"
[1] "Hello, world!"
[1] "Hello, world!"
[1] "Hello, world!"
[1] "Hello, world!"
[1] "Hello, world!"

これで無事GitHubからパッケージをインストールできました。既に全世界のユーザーがあなたのパッケージをダウンロードし使用できる状態です。

おわりに

いかがでしたでしょうか?この記事をベースにして、皆さまが素晴らしいパッケージを開発して世の中に公開していければ幸いです。

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