class: center, middle, inverse, title-slide # R Package Development ### Jay Lee ### 2019/03/18 --- # Motivation ```r library(ggplot2) ggplot(data = mtcars) + geom_bar(aes(x = factor(cyl), fill = factor(gear))) ``` <img src="r_pkg_devel_files/figure-html/unnamed-chunk-1-1.png" width="576" /> --- # Code/Function Reuse - Copy and paste from existinig code snippets - source("path/to/commonly/used/functions.R") - .Rprofile - library(my_awesome_pkg) --- # Cheet Sheet - Create an R package Project from RStudio - Change project options to use roxygen2 - Delete R/hello.R, man/hello.Rd, and (default) NAMESPACE - Iterate through: write/load/document/check/install - Build source and share --- class: center, middle # R Package Development Screenshots --- ## Create a new R project .center[![project](../img/new_project.png)] --- ## New Directory .center[![directory](../img/new_directory.png)] --- ## New R Package .center[![pkg](../img/new_r_pkg.png)] --- ## Naming is hard but fun! .center[![pkg](../img/new_pkg_name.png)] --- ## Naming is hard but fun! .center[![pkg](../img/new_pkg_name_ready.png)] --- ## Hello World! .center[![pkg](../img/hello_world.png)] --- ## Bye World! .center[![pkg](../img/delete_hello_1.png)] --- ## Bye World! .center[![pkg](../img/delete_hello_2.png)] --- ## Bye World! .center[![pkg](../img/delete_hello_man_1.png)] --- ## Bye World! .center[![pkg](../img/delete_hello_man_2.png)] --- ## Bye (Default) NAMESPACE! .center[![pkg](../img/delete_namespace_1.png)] --- ## Bye (Default) NAMESPACE! .center[![pkg](../img/delete_namespace_2.png)] --- ## Change Project Options .center[![pkg](../img/project_option.png)] --- ## Check Roxygen .center[![pkg](../img/roxygen.png)] --- ## Roxygen Option Not Available? - install.packages("roxygen2") - Save and restart RStudio Project (optional) - Return to Project Option --- ## Check Roxygen .center[![pkg](../img/roxygen_options.png)] --- ## Check Roxygen .center[![pkg](../img/roxygen_ready.png)] --- ## Write R Functions .center[![pkg](../img/new_r_script.png)] --- ## Write R Functions .center[![pkg](../img/r_script_name.png)] --- ## Load All Functions (cmd-shift-L) .center[![pkg](../img/load_all.png)] --- ## Load All Functions (cmd-shift-L) .center[![pkg](../img/load_all_done.png)] --- ## Load All Not Available? - install.packages("devtools") - Save and restart RStudio Project - Return to Build menu --- ## Document .center[![pkg](../img/insert_doc.png)] --- ## Document .center[![pkg](../img/doc_done.png)] --- ## Generate Documents (cmd-shift-D) .center[![pkg](../img/generate_doc.png)] --- ## Generate Documents (cmd-shift-D) .center[![pkg](../img/check_doc.png)] --- ## Check (cmd-shift-E) .center[![pkg](../img/check_pkg.png)] --- ## Check Progress .center[![pkg](../img/check_progress.png)] --- ## Check Warnings .center[![pkg](../img/check_warning.png)] --- ## Check Warning Fixed .center[![pkg](../img/check_warning_fixed1.png)] --- ## Nitpicky Warnings/Notes - Title Case - Description period. - Fix license - Etc. --- ## Check Warning Fixed .center[![pkg](../img/check_warning_fixed2.png)] --- ## Install and Restart (cmd-shift-B) .center[![pkg](../img/install.png)] --- ## Build Source .center[![pkg](../img/build_src.png)] --- ## Build Source .center[![pkg](../img/build_src_progress.png)] --- ## Share with coworkers - Copy zipped source file to a common location - install.packages("path/to/source", repos = NULL) --- ## Share with Strangers .center[![pkg](../img/setup_git.png)] --- ## Git Set! .center[![pkg](../img/restart_after_git.png)] --- ## Git Pane .center[![pkg](../img/git_pane.png)] --- ## Create Github Repo .center[![repo](../img/create_github_repo.png)] --- ## Initiate Github Repo .center[![init](../img/init_remote.png)] --- ## First Commit! .center[![pkg](../img/commit.png)] --- ## devtools::install_github ```r library(devtools) devtools::install_github("joongsup/demor") library(demor) demor_ht(mtcars) ``` --- class: center, middle # Thanks!