--- title: "Package Development Day 1" author: "Joyce Robbins" output: github_document --- ```{r setup, include=FALSE, cache=FALSE} knitr::opts_chunk$set(fig.align='center', echo = TRUE, eval=FALSE) ``` # Welcome Joyce Robbins [jtr13\@columbia.edu](mailto:jtr13@columbia.edu) Twitter: \@jtrnyc Thank you to Emily Dodwell and Erin Grand of RLadiesNYC for organizing. Thank you to Mine Çetinkaya-Rundel and Emma Rand of RForwards for developing package development workshop modules. ```{r, echo=FALSE} knitr::include_graphics("images/ty.jpg") ``` # Misha update ```{r, fig.width=5} knitr::include_graphics("images/misha.jpeg") ``` # What are packages? - Collections of code # Where are they stored? - CRAN - GitHub - BioConductor - Your hard drive # How to install - from CRAN: ```{r} install.packages("assertthat") ``` ```{r} install.packages("RLadivmhgfkjhgljkhklhgjesnyc") ``` - from GitHub: ```{r} devtools::install_github("jtr13/ggformat") ``` ```{r} devtools::install_github("jtr13/ggformat", force = TRUE) ``` Many packages are available both on CRAN and GitHub: "dev version" ```{r} devtools::install_github("tidyverse/forcats") ``` - from your hard drive: ```{r} devtools::install("~/ggformat") ``` Regardless of the method, the packages are *installed* -- see Packages --> # What is a "source" package? ```{r} fs::dir_tree("~/ggformat") ``` ```{r} list.files("~/ggformat") ``` # Why use projects? So you never have to use `getwd()` or `setwd()` again. You're always just in the right place. # Loading vs. installing Usually we use `library()` to load packages into memory. While developing a package we use `devtools::load_all()`. - It doesn't show up in the list of packages (or at least the version under development doesn't.) - The functions are in memory and will disappear if we restart R. # Creating a package We need some essential files: `DESCRIPTION` and a folder called `R` with `.R` files. The easier way to create the structure is with `create_package()`: ```{r} library(devtools) create_package("~/covidtime") ``` # YOUR TURN See [Day1_lab.md](Day1_lab.md) # Using the package in another project / script Before we can use the package elsewhere we need to: - add function documentation by clicking "Code... Insert Roxygen Skeleton" (or at a minimum include `@export`) - edit DESCRIPTION - document with `devtools::document()` - install the package with `devtools::install()` # YOUR TURN See [Day1_lab.md](Day1_lab.md) # Package states ```{r, echo=FALSE} knitr::include_graphics("images/installation.png") ``` Source: Key points: - `devtools::install()`: source --> installed - `install.packages()`: binary --> installed - Developers submit *bundles* to CRAN, CRAN builds and distributes *binaries* # Closer look at package files DEMO # Adding git/GitHub ```{r} usethis::usegit() usethis::usegithub() ``` To set default branch from master to main, execute the following in the terminal: `git config --global init.defaultBranch main`