Upgrade to Pro — share decks privately, control downloads, hide ads and more …

OSSベースでのRパッケージ開発のすすめ / rjpusers2021rpkgdev

Uryu Shinya
December 18, 2021

OSSベースでのRパッケージ開発のすすめ / rjpusers2021rpkgdev

2021年12月18日開催「2021年度 データ解析環境Rの整備と利用」 https://rjpusers.connpass.com/event/233211/

Uryu Shinya

December 18, 2021
Tweet

More Decks by Uryu Shinya

Other Decks in Research

Transcript

  1. 044ϕʔεͰͷ
    ύοέʔδ
    ։ൃͷ͢͢Ί
    ӝੜਅ໵ʢಙౡେֶσβΠϯܕ"*ڭҭݚڀηϯλʔʣ
    ೥౓σʔλղੳ؀ڥ3ͷ੔උͱར༻
    !V@SJCP

    View full-size slide

  2. ӝੜਅ໵ 6SZV4IJOZB

    ࣗݾ঺հ
    V@SJCP
    ಙౡେֶσβΠϯܕ"*ڭҭݚڀηϯλʔ
    ॿڭʢ೥݄ʙʣ
    VSJCP
    3ݚڀूձॳൃදʢ-5Λআ͘ʣ
    ۭؒ෼ੳʢ؍ޫܦࡁɺӸֶʣ

    View full-size slide

  3. jpmesh
    ɹύοέʔδ঺հ
    jpndistrict
    ʙ

    ssrn
    fgdr
    zipangu
    sudachir
    tabularmaps
    kuniezu
    oEmbed
    colorinfo
    washoku
    jmastats
    textlintr
    sealr
    easyestat
    ma
    ff
    census
    wakatimer
    CRANొ࿥ޙɺ࡟আ
    CRANొ࿥ࡁΈ
    jpops
    kuniumi r2hue

    View full-size slide

  4. 5PLVTIJNB3اըத
    ࠂ஌ɾએ఻
    ٬һ।ڭत
    ಙౡɾ࢛ࠃΛ3ɺσʔλαΠΤϯεͰ੝Γ্͍͛ͨ

    ಙౡେֶڭһɺֶੜ
    ݝ಺֎ͷؔ܎ऀɺࢢຽ
    גࣜձࣾϗΫιΤϜ
    ڠྗاۀ

    View full-size slide

  5. 044Ͱύοέʔδ։ൃΛ࢝ΊΑ͏

    View full-size slide

  6. ύοέʔδʁ

    View full-size slide

  7. ύοέʔδ3ͷػೳ֦ு
    $3"/ 5IF$PNQSFIFOTJWF3"SDIJWF/FUXPSL

    ύοέʔδ਺ʜ ೥݄೔࣌఺


    Ϣʔβ͕ར༻Մೳͳػೳ
    ʢσʔληοτɺσʔλಡΈࠐΈɺՃ޻ɺՄࢹԽɺ౷ܭॲཧͳͲͳͲʣ
    Λఏڙ
    install.packages("jpmesh") library(jpmesh) jpmesh::as_meshcode("5033")

    View full-size slide

  8. 044Ͱύοέʔδ։ൃΛקΊΔཧ༝
    ໰୊ղܾɺػೳ௥Ճͷ଎౓Λ޲্
    ։ൃҙཉͷҡ࣋
    ίϛϡχςΟɺݚڀ΁ͷߩݙ




    View full-size slide

  9. ⁞ίϛϡχςΟɺݚڀ΁ͷߩݙ
    > R is free software distributed under a GNU-style copyleft.
    IUUQTTWOSQSPKFDUPSH3 IUUQTCVHTSQSPKFDUPSH
    IUUQTHJUIVCDPNSTUVEJPSTUVEJP
    044Ͱ͋Δ͜ͱ͸3ίϛϡχςΟͷจԽͱͯ͠ී௨

    View full-size slide

  10. ࿦จʹؔ͢ΔҰ࿈ͷίʔυΛެ։
    IUUQTHJUIVCDPNOJFTDPOTQMBOFOWDG
    ,VCP 5 7FSÍTTJNP % 6SZV 4FUBM8IBUEFUFSNJOFTUIFTVDDFTTBOEGBJMVSFPGFOWJSPONFOUBMDSPXEGVOEJOH
    "NCJP
    IUUQTEPJPSHT
    ࿦จͷ࠶ݱੑΛอূɺޙܧͷਓʑͷͨΊʹ࢒͓ͯ͘͠

    View full-size slide

  11.  ໰୊ղܾɺػೳ௥Ճͷ଎౓Λ޲্
    ֎ͷۭؾʹ৮ΕΔ͜ͱͰࢥΘ͵ʮԽֶ൓ԠʯΛى͔͜͢΋
    IUUQTHJUIVCDPNVSJCP[JQBOHVHSBQITDPOUSJCVUPST
    ϦϨʔͷΠϝʔδ
    044
    ݸਓ΋͘΋͘
    Θ͔ΒΜʜ
    ։ൃ଎౓͕௿Լ͢Δظؒ
    ʮͭ·͖ͮʯʹର͢Δऑ͞
    Θ͔ΒΜʜ ೚ͤͯʂ

    View full-size slide

  12. ⁠։ൃҙཉͷҡ࣋
    ͜·ΊͳΞ΢τϓοτ͕ηʔϒϙΠϯτͱͳΔ
    ֎෦΁ൃදɾࠂ஌
    ڏແײ
    (JU)VC(JU-BCͰͷެ։
    ࠳ં͢ΔڪΕ
    ݽಠ
    ࣗ༝ʹ
    ޷͖ͳ΋ͷΛ
    5X
    JUUFS
    ˠ$3"/ొ࿥ͤͣʹར༻ͯ͠΋Β͑Δ
    5PLZP3ͳͲͷίϛϡχςΟ
    ϒ
    ϩ
    ά
    ϑΟʔυόοΫΛಘ΍͍͢
    044
    ݸਓ΋͘΋͘

    View full-size slide

  13. 044Ͱ։ൃதͷ3ύοέʔδͷ঺հ

    View full-size slide

  14. Ϟνϕʔγϣϯ
    3ݴޠ΁ͷڵຯ
    "1*Λར༻ͯ͠Έ͍ͨ
    ஍ཧۭؒσʔλͷॲཧΛ
    ೔ຊޠपΓͷ໰୊ʹ
    ࣗ෼ͷ޷͖ͳ͜ͱΛ͍ͨ͠
    ॳظ
    தظ
    ݱࡏ
    ָʹ͍ͨ͠
    ରԠ͍ͨ͠
    ٕज़తͳؔ৺

    View full-size slide

  15. KQNFTI
    ඪ४஍ҬϝογϡΛѻ͏
    ,VCP 5 6SZV 4FUBM
    .PCJMFQIPOFOFUXPSLEBUBSFWFBMOBUJPOXJEFFDPOPNJDWBMVFPGDPBTUBMUPVSJTNVOEFSDMJNBUFDIBOHF
    5PVSJTN.BOBHFNFOU
    IUUQTEPJPSHKUPVSNBO
    library(jpmesh)


    meshcode(5133) # 80km


    #>


    #> [1] 5133


    meshcode(5133778300, .type = "subdivision")


    #>


    #> [1] 5133778300


    mesh_to_coords(51337783)


    #> # A tibble: 1 × 5


    #> meshcode lng_center lat_center lng_error lat_error


    #>


    #> 1 51337783 134. 34.7 0.00625 0.00417


    coords_to_mesh(133, 34)


    #>


    #> [1] 51330000


    # Scale down


    mesh_convert("52350432", 0.500)


    #>


    #> [1] 523504321 523504322 523504323 523504324


    # Find out neighborhood meshes


    meshcode(5133) %>%


    neighbor_mesh(contains = TRUE)


    #>


    #> [1] 5032 5033 5034 5132 5133 5134 5232 5233 5234

    View full-size slide

  16. GHES
    ࠃ౔஍ཧӃ͕ఏڙ͢Δج൫஍ਤ৘ใͷॲཧ
    3ͱ%ϓϦϯλʔͰീϲַͷϛχνϡΞΛ࡞Δɻ
    IUUQTCMPHIPYPNDPNFOUSZ
    ར༻ࣄྫ ߟݹֶͷͨΊͷ3Ͱ(*4ʔϥελฤ
    IUUQTRJJUBDPNJTIJJKVOQFJJUFNTBCDCFFECGCCB
    library(fgdr)


    # جຊ߲໨


    read_fgd("FG-GML-523346-AdmPt-20180701-0001.xml")


    # ਺஋ඪߴϞσϧ


    read_fgd_dem("FG-GML-5135-63-00-DEM5A-20161001.xml", resolution = 5, return_class = "data.table")

    View full-size slide

  17. [JQBOHV
    ೔ຊޠपΓͷ໰୊Λղܾ͢ΔศརͳػೳΛఏڙ
    IUUQTHJUIVCDPNVSJCP[JQBOHVJTTVFT
    library(zipangu)


    convert_jyear("R3")


    #> [1] 2021


    convert_jdate("ྩ࿨̏೥12݄18೔")


    #> [1] "2021-12-18"


    # ॕ೔ͷ൑ఆ


    #ʢఱߖ஀ੜ೔ɺΦϦϯϐοΫؔ܎ͷΧϨϯμʔͷมߋʹ΋ରԠʣ


    is_jholiday("2018-12-24")


    #> [1] TRUE


    is_jholiday("2021-12-24")


    #> [1] FALSE


    is_jholiday("2022-01-10")


    #> [1] TRUE


    kansuji2arabic(c("Ұ", "ඦ"))


    #> [1] "1" "100"


    # ฦΓ஋Λ਺஋


    kansuji2arabic(c("Ұ", "ඦ"), convert = FALSE)


    #> [1] 1 100
    # Nipponύοέʔδʹͳ͔ͬͨؔ਺


    separate_address("౦ژ౎ઍ୅ా۠େखொҰஸ໨")


    #> $prefecture


    #> [1] "౦ژ౎"


    #>


    #> $city


    #> [1] "ઍ୅ా۠"


    #>


    #> $street


    #> [1] "େखொҰஸ໨"


    harmonize_prefecture_name(


    c("౦ژ", "๺ւಓ", "ԭೄ"),


    to = "long")


    #> [1] "౦ژ౎" "๺ւಓ" "ԭೄݝ"

    View full-size slide

  18. KNBTUBUT
    ୆෩
    ؾ৅ிͷσʔλΛऔಘɾ੔ܗͯ͠ఏڙ
    # ਒౓σʔλϕʔε ਒౓Ϧετ


    read_eqdb_csv(path = "਒ݯɾ਒౓Ϧετ.csv")


    #>


    #> ஍਒ͷ֓ཁ


    #> x ൃੜ೔࣌: 2021-11-09 01:14:57


    #> x ਒ԝ஍໊: ෱ౡݝத௨Γ


    #> • Ң౓: 37°03.7′N


    #> • ܦ౓: 140°35.0′E


    #> ! ਂ͞: 6 km


    #> ! Ϛάχνϡʔυ: 4.9


    #> ! ࠷େ਒౓: ਒౓̐


    #> # A tibble: 472 × 4


    #> ౎ಓ෎ݝ ਒౓ ؍ଌ఺໊ ؾ৅ிͷ਒౓؍ଌ఺


    #>


    #> 1 ෱ౡݝ 4 ݹ఼ொদ઒ԣ઒ TRUE


    #> 2 ෱ౡݝ 4 ݹ఼ொদ઒৽܂ݪ FALSE


    #> 3 ෱ౡݝ 3 ఱӫଜԼদຊ FALSE


    #> 4 ෱ౡݝ 3 ୨૔ொ୨૔தډ໺ TRUE


    #> 5 ෱ౡݝ 3 伸઒ଜ੺ࡔத໺ FALSE


    #> 6 ෱ౡݝ 3 ੴ઒ொ௕ٱอ FALSE


    #> 7 ෱ౡݝ 3 ۄ઒ଜখߴ FALSE


    #> 8 ෱ౡݝ 3 ઙ઒ொઙ઒ FALSE


    #> 9 ෱ౡݝ 3 ͍Θ͖ࢢࡾ࿨ொ TRUE


    #> 10 ෱ౡݝ 2 ܊ࢁࢢே೔ TRUE


    #> # … with 462 more rows
    library(jmastats)


    # ஍఺ؾ৅σʔλ


    jma_collect(item = "hourly", block_no = 47646, year = 2021, month = 11, day = 27)


    # ۙ๣ͷؾ৅؍ଌ஍఺ͷݕࡧ


    nearest_station(longitude = 140.112, latitude = 36.083)


    #> Simple feature collection with 1 feature and 5 fields


    #> Geometry type: POINT


    #> Dimension: XY


    #> Bounding box: xmin: 140.125 ymin: 36.05667 xmax: 140.125 ymax: 36.05667


    #> Geodetic CRS: WGS 84


    #> # A tibble: 1 × 6


    #> area station_no station_name block_no distance geometry


    #> [m]


    #> 1 Ἒ৓ 40336 ͭ͘͹ 47646 3153. (140.125 36.05667)
    ைҐ ஍਒

    View full-size slide

  19. 044Ͱͷ։ൃʹΑΔ෭࡞༻
    ৽͍ٕ͠ज़ɺύοέʔδʹ৮ΕΔ
    TVEBDIJSʜSFUJDVMBUF 1ZUIPO

    GHESʜTUBST UFSSB
    ৽ػೳͷఏҊɺղܾࡦͷΞΠσΞɺڠྗऀ
    [JQBOHVʜΩϟογϡɺϕΫτϧԽɺ׽਺ࣈͷॲཧ
    044ɾ5XJUUFS
    ύοέʔδ։ൃ
    UFYUMJOUSʜ+BWB4DSJQU
    KNBTUBUTʜைҐදɺ਒౓σʔλϕʔε
    Ͱ͖ͨΑʔ
    ΋ͷͮ͘Γͷָ͠͞
    ♥ ⭐
    XBTIPLVʜSFDJQFT WDUST

    View full-size slide

  20. ύοέʔδ։ൃʹ௅Ήਓͨͪ΁

    View full-size slide

  21. ݚڀऀʹקΊ͍ͨύοέʔδͷछྨ
    छྨ ֶज़ݚڀͷଆ໘ ඞཁͳٕज़ྗ ύοέʔδྫ
    ղੳख๏ͷ࣮૷ ଟ͍ গͳ͍ʙଟ͍ TVEBDIJS TTSO XBTIPLV
    σʔλ੔ܗɾՃ޻ ී௨ ී௨ʙଟ͍ KQNFTI GHES [JQBOHV
    ՄࢹԽ গͳ͍ ଟ͍ UBCVMBNBQT
    ੾Γޱ͸ଟ༷ɻ՝୊ʹదͨ͠ύοέʔδͷछྨ͕͋Δ

    View full-size slide

  22. ݚڀ׆ಈͱͯ͠ͷධՁ
    3ύοέʔδͷ։ൃɺ؅ཧΛஂମͰӡӦ
    IUUQTHJUIVCDPNPQFOKPVSOBMTKPTTSFWJFXT
    IUUQTHJUIVCDPNSPQFOTDJ
    S0QFO4DJ
    (JU)VCJTTVFTͰͷϨϏϡʔΛ௨ͯ͠%0*͕༩͑ΒΕΔ
    ݚڀ༻ιϑτ΢ΣΞͷͨΊͷΦʔϓϯΞΫηεδϟʔφϧ
    5IF+PVSOBMPG0QFO4PVSDF4PGUXBSF +044

    ϨϏϡʔ৹ࠪ͋Γ
    ;FOPEP
    IUUQT[FOPEPPSH
    (JU)VCϦϙδτϦͱඥ෇͚ͯ
    %0*Λൃߦ
    KQNFTIͷྫ

    View full-size slide

  23. ஌Βͳ͍࢓༷ɺศརͳUJQT
    ύοέʔδͷ࡞Γํʁ
    ৘ใΛ஌ΔͨΊʹ΋(JU)VC͕༗ޮ
    ͿΒͬ͘΅ͬ͘͢ɺͳཁૉ΋ଟʑʜ
    IUUQTSQLHTPSH
    ʮݟΑ͏ݟਅࣅʯઓུ
    31BDLBHFT
    044Ͱͳ͍ͱ͞Βʹ໎ࢠʹͳΓ΍͍͢
    ೔ຊޠͰಘΒΕΔ৘ใ͸͔ͳΓগͳ͍
    1SBDUJDBM31BDLBHF%FWFMPQNFOU +BQBOFTF

    IUUQTCPPLEPXOPSHZVUBOOJIJMBUJPOQSBDUJDBMSQBDLBHFEFWFMPQNFOUKB

    View full-size slide

  24. Ұॹʹ։ൃɺϊ΢ϋ΢ͷڞ༗
    ͜ΜͳύοέʔδΛ࡞Γ͍ͨ
    ࣗ෼΋Θ͔Βͳ͔ͬͨˍࠓ΋Θ͔ΒΜ
    ٕज़తͳҙຯͰղܾͰ͖ͳ͍
    ΞυϗοΫͳ஌ݟʹͱͲΊͳ͍޻෉
    धཁΛर͑Δମ੍΋࡞͍͖͍ͬͯͨ
    5PLVTIJNB3ʢίϛϡχςΟʣͰࢧԉɾܧঝͰ͖ΔΑ͏ʹ

    View full-size slide

  25. ·ͱΊ
    044Ͱͷύοέʔδ։ൃ͸ָ͍͠ɺ
    ࠃ಺Ͱͷࣄྫ͕·ͩ଍Γͳ͍ɻ
    ίϛϡχςΟ΁ͷߩݙɺݚڀ׆ಈͷҰ؀ͱͯ͠



    ύοέʔδ։ൃΛ࢝ΊΑ͏
    ʢ૯߹తʹʣҰਓͰͷ࡞ۀΑΓෛ୲͕গͳ͍
    5PLVTIJNB3ͳͲͰύοέʔδ։ൃͷٕೳशಘΛ໨ࢦ͢
    ΈΜͳͰ஌ݟΛڞ༗͠Α͏

    View full-size slide