「なければ作る」 「なければ作る」 Sometimes, we look for R packages to do the processing we want to achieve However, the packages we seek may not exist (If we look for it carefully, it will exist) 「なければ作ればいい」
Procedure of R package dev Procedure of R package dev 1. Prepare environment for R package-dev 2. Create repository and R-project 3. Write codes, descriptions, documents 4. Build and Testing 5. Deploy 6. Create the information-site of this package
Applications required for R-package dev Applications required for R-package dev git for version control R RStudio IDE for R web browser for access git(github) and check docs
R packages for dev R packages for dev devtools tool-set of R package dev roxygen2 useful package for generating/modifying descriptions usethis useful package for creating R package testthat for test rmarkdown for rendering documents pkgdown for creating web-site of this package
connect R-package and repository connect R-package and repository Click ‘Terminal’ tab and run these command: git remote add origin (repository_url) git add . git commit -m "first commit" git push --set-upstream origin master This is a kind of samples.
Description method using roxygen2 Description method using roxygen2 Concepts Concepts The premise of roxygen2 is simple: describe your functions in comments next to their definitions and roxygen2 will process your source code and comments to produce Rd files in the man/ directory. How to write How to write It is a easier way to check this cheat sheet: https://www.rstudio.com/resources/cheatsheets/#package
example example from roxygen2 repository: #' The length of a string (in characters). #' #' @param string input character vector #' @return numeric vector giving number of characters in each element of #' character vector. Missing strings have missing length. #' @seealso \code{\link{nchar}} which this function wraps #' @export #' @examples #' str_length(letters) #' str_length(c("i", "like", "programming", NA)) str_length <- function(string) { string <- check_string(string) nc <- nchar(string, allowNA = TRUE) is.na(nc) <- is.na(string) nc }
create documents create documents If you wrote this, you just need to do this: devtools::document() This function create documents. For example, help, vignette, DESCRIPTION(package meta info), NAMESPACE and so on.
Build and test Build and test Click “Install and Restart” button on “Build” tab. After build and installed your package, execute and test the function to see if it works as intended:
Test using testthat Test using testthat If you want to use automated test application(e.g., CircleCI), testthat package may help you. For more detail about testthat, please see the . package site
Edit DESCRIPTION Edit DESCRIPTION You have to edit file … If you want add “package dependency”, use : usethis::use_package("name_of_package", type = "Imports")
Deploy the site Deploy the site 1. git add -> git commit -> git push 2. access github and go to this repository 3. click “Setting” tab 4. activate “GitHub pages” choose “master branch /docs folder” at Source area 5. access and check it
Let’s develop your package easily using Let’s develop your package easily using these packages! these packages! devtools roxygen2 usethis testthat rmarkdown pkgdown https://devtools.r-lib.org/ https://github.com/klutometis/roxygen https://usethis.r-lib.org/index.html https://testthat.r-lib.org/ https://bookdown.org/yihui/rmarkdown/ https://pkgdown.r-lib.org/