Share
Embed
2019年版Rパッケージ開発の手引き / pkg_dev
Uryu Shinya
November 16, 2019
Transcript
45 slides
-
ࢲʹ͍ͭͯ CRAN 5 + (1) GitHub 20+ \TG^ UJEZWFSTF SMJCܥͷύοέʔδͷ$POUSJCVUJPO
Ἒݝͭ͘ࢢ͔Βདྷ·ͨ͠ʢผࢢʣ >1000 km 1SJWBUFؚΉ -
୭ɾԿͷͨΊͷύοέʔδʁ ଞऀ ࣗࣗͷ ࣌ؒͷઅ ڞ༗ ίϛϡχςΟ ٕज़ଅਐ ྫ͑ {magrittr} %>%
{rlang} !!,quo() ڞಉ࡞ۀऀୈࡾऀͷ ख͍ͱͳΔΑ͏ʹ ʢ͕ࣗͦ͏Ͱ͋ΔΑ͏ʹʣ -
ύοέʔδͱԿ͔ جຊతͳύοέʔδʢιʔεύοέʔδʣͷߏ R data man tests .R .R .Rd .Rd
.rds Rout.save .R .Rbuildignore DESCRIPTION LICENSE NEWS README vignettes src inst data-raw ඞཁʹԠͯ͡ ϑΥϧμΛ ஔ ༨ܭͳϑΝΠϧ͕͋Δͱ DIFDLͰౖΒΕΔ -
ύοέʔδ։ൃ·ͰͷྲྀΕ Ұྫ ಈػ͚ طଘͷύοέʔδ͕͋Δʁ ࣮ΠέͯΔʁ վળͳ͍͔ʁ YES NO ؔͷ࣮Մೳʁ *TTVFʹه
13ΛૹΔ 044ͱͯ͠ެ։ʁ ύοέʔδ໊Λߟ͑Δ create_package() ՄจࣈɺࣈɺϐϦΦυ ઌ಄จࣈͰ࢝·Δ͜ͱɺ ඌʹϐϦΦυ͑ͳ͍ -
ύοέʔδ։ൃ·ͰͷྲྀΕ Ұྫ YES NO ؔΛॻ͘ υΩϡϝϯτΛඋ͢Δ ςετίʔυΛ༻ҙ͢Δ ίʔυΛચ࿅ͤ͞Δ ςετɺνΣοΫΛ௨͢ $3"/ొΛࢦ͢
ࠓ͠·ͤΜ test(),check() Ϗϧυͯ͠ڞ༗ɺ044Ͱެ։ (JU)VC͕ओྲྀ ଞʹ(JU-BC#JCVDLFUͳͲ build(),install() -
%&4$3*15*0/ΛຒΊΑ͏ %&4$3*15*0/ͷใ͕ $3"/ʹө͞Ε·͢ Package: spatech Title: What the Package Does
(One Line, Title Case) Version: 0.0.0.9000 Authors@R: person(given = "First", family = "Last", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "YOUR-ORCID-ID")) Description: What the package does (one paragraph). License: What license it uses Encoding: UTF-8 LazyData: true -
%&4$3*15*0/ΛຒΊΑ͏ Package: spatech Title: Oita Spa Tech Sample Version: 0.0.0.9000
Authors@R: person(given = "Shinya", family = "Uryu", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0002-0493-6186")) Description: Guide to first R library development. License: MIT + file LICENSE Encoding: UTF-8 LazyData: true URL: https: //github.com/uribo/spatech BugReports: https: //github.com/uribo/spatech/issues use_github() use_mit_license() .Rprofile ʹઃఆΛهड़͓ͯ͘͠ͱָ author creator contributor copyright holder ։ൃʹܞΘΔਓͷϦετ ?person ৄࡉ -
όʔδϣϯʹ͍ͭͯ ͔ͰࣈΛ۠Δʢࣈ͕ͭҎ্ʹͳΔΑ͏ʹʣ OPW <major>.<minor>.<patch> ͷܗ͕ࣜ·͍͠ ։ൃதͷόʔδϣϯͰ͋Δ͜ͱ͕໌֬ 0.0.0.9000 $3"/ొ࣌ʹόʔδϣϯΛ͋͛Δ $3"/͔ΒΠϯετʔϧ͞ΕΔ൛
ͱҟͳΔ͜ͱΛࣔ͢ 0.0.0.9000 0.1.0 0.1.0.9000 Release Development Development -
ͳΜͷͨΊͷςετʁ όάΛݮΒ͢ ߏ͕ྑ͘ͳΔ ։ൃ͕ଅਐ͞ΕΔ ݎ࿚ੑΛߴΊΔ use_testthat() use_test() devtools ::test() test_that()
expect_*() skip_*() .R test-hoge.R 1 2 3 4 ྭ·͠ͷϝοηʔδ͖ͭ -
ςετʹԿΛॻ͘ʁ ίʔυ͕ͲͷΑ͏ʹৼΔ͏ͷ͔ɺ༧͞ΕΔ݁ՌΛهड़͢Δ hello_msg <- function(name = NULL) { if (is.null(name))
{ warning("Name argument is null") } else { message(paste("Hi,", name)) } } .R msg.R -
ςετʹԿΛॻ͘ʁ ίʔυ͕ͲͷΑ͏ʹৼΔ͏ͷ͔ɺ༧͞ΕΔ݁ՌΛهड़͢Δ expect_message( hello_msg(name = "uribo")) expect_warning( hello_msg()) expect_equal( hello_msg(name
= "uribo"), "Hi, uribo") #> Hi, uribo #> Error: hello_msg(name = "uribo") not equal to "Hi, uribo". #> target is NULL, current is character .R test-msg.R ؔͷڍಈΛΔͨΊʹ UFTUͷϑΝΠϧΛݟΔͷ ྑ͍ -
ڞ༗ଞऀͷར༻Λఆ SIVC XJOCVJMEFS ܧଓత ΠϯςάϨʔγϣϯ αʔϏε ύοέʔδɺΣϒαʔϏεɺEPDLFSڥΛ׆༻ͨ͠ςετΛ࣮ࢪ https://builder.r-hub.io/ \SIVC^͔Β ϚϧνϓϥοτϑΥʔϜͰͷCVJME
https://win-builder.r-project.org/ EFWUPPMTDIFDL@XJO@ https://travis-ci.org .BD04Ϣʔβ͕8JOEPXTڥΛ ࢼ͢ͷʹॏๅ https://circleci.com -
SPYZHFOίϝϯτ !UBHͷܗࣜ `Ͱ࢝·Γɺରͷؔͷલʹهड़͢Δ @inheritParams @rdname @export {roxygen2md} {roxygen2} ॏཁͳͷ @param
@description SPYZHFOλά·ͱΊc"UVTZTCMPH https://blog.atusy.net/2018/08/28/roxygen2matome/ SPYZHFOίϝϯτʹNBSLEPXOه๏ ΛՄೳʹ͢Δʢ3EϑΝΠϧੜ࣌ʹมʣ ؔͷΤΫεϙʔτ Ҿͷܧঝ -
#' @title Read and Parse Fundamental Geospatial Data (FGD) file
#' #' @description The JPGIS (GML) format file provided by FGD as input, #' the fundamental items in the file is read as an 'sf' object. #' Supporting FGD Version 4.1 (2016/10/31). #' @details Support following items: #' Administrative Area ('AdmArea'), Administrative Boundary ('AdmBdry'), #’ … লུ #' @seealso \url{https: //fgd.gsi.go.jp/download/ref_kihon.html} #' @param file Path to XML file #' @import sf #' @import xml2 #' @importFrom purrr pmap reduce list_modify #' @importFrom tibble new_tibble #' @return A [sf][sf ::st_sf] #' @export #' @examples #' # Administrative Area #' read_fgd(system.file("extdata/FG-GML-000000-AdmPt-dummy.xml", package = "fgdr")) ?fgdr ::read_fgd()