21 Temmuz 2014 Pazartesi

R da (Elle ve Otomatik) Paket Oluşturumu [tr]

ELLE PAKET YAPIMI
Oluşturulacak paketin adı, paket1 olsun.
0. Gerekli paketleri yükle:
library(roxygen2)
library(devtools)
library(digest)
1. R’ın çalışma dizininde (C:/Users/erdogan/Documents/Revolution) paket1 adlı dizin (klasör) oluştur (R>list.files() ile çalışma dizininde oluşturulan dosya ve klasörler görülebilir).
2. paket1 dizininde, DESCRIPTION adlı bir dosya oluştur ve aşağıdaki içeriği DESCRIPTION’ın içine koy (dilediğin gibi DESCRIPTION’ı düzenle)(Başka bir paketin DESCRIPTION’ınını da koyup, R’da “Dosya – Aç – Dosya...- DESCRIPTION” ile koyduğun bu DESCRIPTION’ı istediğin gibi değiştirebilirsin):
DESCRIPTION
Package: paket1
Type: Package
Title: What the package does (short line)
Version: 0.0.1
Date: 2012-11-12
Author: Who wrote it
Maintainer: Who to complain to <yourfault@somewhere.net>
Description: More about what it does (maybe more than one line)
License: GPL
3. paket1 dizininde, “R” adlı dizin oluştur ve her işlevin .r dosyasını ekle (veya istersen tüm işlevlerini aynı dosyaya koyabilirsin). Üç dosya oluşturdum: islev1.R, islev2.R, islev3.R
islev1.R
#' islev1
#' @param x numeric
#' @export
islev1 <- function(x){
    rnorm(100*x)
}
islev2.R
#' islev2
#' @param y numeric
#' @export
islev2 <- function(y){
    rnorm(200*y)
}
islev3.R
#' islev3
#'
#' This is the Description section
#'
#' This is the Details section
#'
#' @param x numeric. this is multiplied by 100 to determine the length of the returned vector
#' @return a numeric vector of random deviates of length \code{100 * x}
#' @author your name
#' @seealso \code{\link{fun2}}
#' @examples
#' islev3(2)
#' length(fun3(20))
#' @export
islev3 <- function(x){
    rnorm(100*x)
}
4. Oluşturulacak paket, roxygenize et:
roxygenize("paket1")
Updating collate directive in  /home/garrett/tmp/package1/DESCRIPTION
Updating namespace directives
Writing islev1.Rd
Writing islev2.Rd
Writing islev3.Rd
build("paket1")
install("paket1")
library(paket1)
islev1(20)
------------------------------------------------------------------------------------------------------
OTOMATİK PAKET YAPIMI
Oluşturulacak paketin adı, paket3 olsun.
0. Gerekli paketleri yükle:
library(roxygen2)
library(devtools)
library(digest)
1. Pakette yer alacak işlevlerin .R dosyalarını (islevv1.R, islevv2.R, islevv3.R) R’ın çalışma dizinine (C:/Users/erdogan/Documents/Revolution) koy. 
package.skeleton(name = "paket3", code_files = c("islevv1.R","islevv2.R", "islevv3.R"), path = ".")
komutu sonrasında R’nin çalışma dizininde aşağıdaki klasörler ve dosyalar oluşur:
> list.files("paket3", recursive=TRUE)
 [1] "DESCRIPTION"           "man/islevv1.Rd"        "man/islevv2.Rd"      
 [4] "man/islevv3.Rd"        "man/paket3-package.Rd" "NAMESPACE"           
 [7] "R/islevv1.R"           "R/islevv2.R"           "R/islevv3.R"         
[10] "Read-and-delete-me"

Read-and-delete-me dosyasını Windows Explorer’a gidip sil.

DESCRIPTION
Package: paket3
Type: Package
Title: What the package does (short line)
Version: 1.0
Date: 2014-07-18
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?
NAMESPACE
exportPattern("^[[:alpha:]]+")

2. Oluşturulacak paketi, roxygenize et:
roxygenize("paket3")
Updating collate directive in  /home/garrett/tmp/package1/DESCRIPTION
Updating namespace directives
Writing islev1.Rd
Writing islev2.Rd
Writing islev3.Rd

roxygenize sonrasında: klasörler ve dosyaların yeni durumu:
NAMESPACE
# Generated by roxygen2 (4.0.1): do not edit by hand

export(islevv1)
export(islevv2)
export(islevv3)

build("paket3")
[1] "C:/Users/erdogan/Documents/Revolution/paket3_1.0.tar.gz"

install("paket3")
Bu aşamada, “paket3-package.Rd:33: All text must be in a section” hatası alırsan, çalışma dizinindeki paket3 dizinindeki man’ın altındaki paket3-package.Rd dosyasını sil ve install("paket3") komutunu yeniden çalıştır. Bu sefer hata almazsın.

library(paket3)

islevv1(20)

Hiç yorum yok:

Yorum Gönder