Каждая домохозяйка должна уметь создать пакет для R

Для выпечки своего домашнего пакета R потребуется установить пакеты devtools — для удобства инсталляции и roxygen2 — для документирования.

Написание своего пакета под Windows — дело более хлопотное и здесь не рассматривается. Ходит слух, что надо установить RTools, но может и кое-что похуже. Эти инструкции относятся к macos и linux.

Первичное создание пакета

Package: honey
Type: Package
Title: R package to get honey.
Version: 0.1
Date: 2014-07-25
Author: Winni-the-Pooh
Maintainer: Winni-the-Pooh <xxx.yyy@zzz.com>
Description: This package contains functions useful to distinguish good and bad bees.
License: MIT
#' Evaluates the amount of good honey given the tree
#'
#' The amount of honey is estimated using the latest mcmc methods.
#'
#' @param tree the tree for which the amount of honey is estimated
#' @return numeric the estimated amount of good honey
#' @export
#' @examples
#' honey_evaluate(tree)
#' honey
#'
#' @name honey
#' @docType package
#' @author Winnie-the-Pooh 
#' @import MCMCpack ggplot2
NULL
#' Data on honey prices
#'
#' A dataset containing xxx The variables are as follows:
#'
#' \itemize{
#' \item pot the number of honey pot
#' \item price the price of the pot in rubbles
#' }
#'
#' @docType data
#' @keywords datasets
#' @name honey_price
#' @usage data(honey_price)
#' @format A data frame with xxx rows and yyy variables
NULL

Типичный сценарий работы над пакетом

require("devtools")
require("roxygen2")
setwd("honey")

dev_mode()
document()
install("../honey")
require("honey")
dev_mode(FALSE)

Загрузка пакета

Любой другой человек сможет установить наш пакет командами

require("devtools")
install_github("username/honey")

здесь вместо username подразумевается гитхабовское имя владельца пакета.

И далее использовать после обычного

require("honey")