background-image: url(https://i.imgur.com/CVIZGyY.jpg) background-position: top background-size: 100% class: inverse, shadow # My Organization's First R package ## Setup R Packages ## `rstudio::conf(2020L)` --- class: middle, center <img src="img/where_are_we_01.png" width="100%" height="100%" style="display: block; margin: auto;" /> --- background-image: url(http://hexb.in/hexagons/devtools.png) background-position: 90% 10% # [devtools](https://devtools.r-lib.org/) -- .pull-left[ ## Tools to make an R developer's life easier ## Well be using functions like *`load_all()`*, *`build()`*, *`document()`*, *`test()`*, and *`check()`* throughout the day. ] --- background-image: url(https://raw.githubusercontent.com/r-lib/usethis/master/man/figures/logo.png) background-position: 90% 10% # [usethis](https://usethis.r-lib.org/) -- .pull-left[ ## Set up commonly used 📦 components ## Well be using functions like *`create_package()`*, *`use_r()`*, *`use_test()`*, and many more throughout the day. ] --- background-image: url(img/hex-shinRa.png) background-position: 90% 10% background-size: 30% # shinRa .pull-left[ ## An R package for the data science team at the Shinra Electric Power Company, also known as Shinra, Inc. ## What will it do? Custom ggplot2 themes, reports, data connections and filtering, and more. ] --- # `create_package("shinRa")` ```r library(usethis) create_package("shinRa") ``` --- ```r library(usethis) create_package("shinRa") ``` .small[ ``` ## ✔ Creating '/var/folders/03/9x7925g54mncswxx06wpkxl00000gn/T/Rtmp7tPPPb/file7084271a9342/shinRa/' ## ✔ Setting active project to '/private/var/folders/03/9x7925g54mncswxx06wpkxl00000gn/T/Rtmp7tPP... ## ✔ Creating 'R/' ## ✔ Writing 'DESCRIPTION'``` ``` ## Package: shinRa ## Title: What the Package Does (One Line, Title Case) ## Version: 0.0.0.9000 ## Authors@R (parsed): ## * First Last <first.last@example.com> [aut, cre] (<https://orcid.org/YOUR-ORCID-ID>) ## Description: What the package does (one paragraph). ## License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a ## license ## Encoding: UTF-8 ## LazyData: true ## Roxygen: list(markdown = TRUE) ``` ``` ## ✔ Writing 'NAMESPACE' ## ✔ Writing 'shinRa.Rproj' ## ✔ Adding '.Rproj.user' to '.gitignore' ## ✔ Adding '^shinRa\ \.Rproj$', '^\\.Rproj\\.user$' to '.Rbuildignore' ## ✔ Setting active project to '/private/var/folders/ 03/9x7925g54mncswxx06wpkxl00000gn/T/Rtmp7tP...``` ``` ## /var/folders/03/9x7925g54mncswxx06wpkxl00000gn/T//Rtmp7tPPPb/file7084271a9342/shinRa ``` ] --- <img src="img/create_package.png" width="100%" height="100%" style="display: block; margin: auto;" /> --- <img src="img/create_package_hidden.png" width="100%" height="100%" style="display: block; margin: auto;" /> --- <img src="img/create_package_description.png" width="100%" height="100%" style="display: block; margin: auto;" /> --- <img src="img/create_package_namespace.png" width="100%" height="100%" style="display: block; margin: auto;" /> --- <img src="img/create_package_r.png" width="100%" height="100%" style="display: block; margin: auto;" /> --- <img src="img/create_package_rproj.png" width="100%" height="100%" style="display: block; margin: auto;" /> --- ## Your Turn 1 #### Load usethis and devtools if you haven't. #### Open the DESCRIPTION file and take a look. It's very generic! #### Run `edit_r_profile()`. Copy and paste this code into your R profile, but change it to your name and email. If you would like to add your ORCID ID see `?use_description` for an example for an example that includes that. #### Then, restart your R session (Session > Restart R). if you don't want to change your R profile, you can just run the code in the console without running `edit_r_profile()` or restarting #### When you've restarted, run `use_description()` to replace the DESCRIPTION file. #### Open the DESCRIPTION file and take a look around. --- ## Your Turn 1: Stretch Goal #### Read the help page for `use_usethis()`. If there are any of these that you'd like available in all interactive sessions, run the function to get the related code and add it to your R Profile. --- background-image: url(img/hex-avalanchr.png) background-position: 90% 10% background-size: 30% # avalanchr .pull-left[ ## An R package for the data science team for the AVALANCHE ecological insurgency organization. ] --- <img src="img/description.png" width="100%" height="100%" style="display: block; margin: auto;" /> --- <img src="img/description_pkgname.png" width="100%" height="100%" style="display: block; margin: auto;" /> --- class: inverse # Valid package names: 1. Consist of letters, numbers, or periods. 2. Start with a letter. 3. Do *not* end with a period --- class: center, middle, inverse # **Use the [available](https://github.com/r-lib/available) package to check your package name** --- ## Naming your package ```r available::suggest("Shinra Electric Power") ``` ``` ## shinrar ``` -- ## Also see ["Naming Things"](https://www.njtierney.com/post/2018/06/20/naming-things/) --- ## Is the name available? ```r available::available("package.name") ``` -- <img src="img/available.png" width="80%" height="80%" style="display: block; margin: auto;" /> .pull-left[Image from the [available repository](https://github.com/r-lib/available)] --- <img src="img/description_title.png" width="100%" height="100%" style="display: block; margin: auto;" /> --- <img src="img/cran-package.png" width="90%" height="90%" style="display: block; margin: auto;" /> .pull-right[image from [R Packages, ed. 2](https://r-pkgs.org/description.html)] --- <img src="img/description_author.png" width="100%" height="100%" style="display: block; margin: auto;" /> --- # Adding an author with desc -- ```r *desc::desc_add_author( given = "Rufus", family = "Shinra", role = "ctb", email = "rufus@shinrainc.com", comment = list("ORCID-ID" = "902348-439034") ) ``` --- # Adding an author with desc ```r desc::desc_add_author( * given = "Rufus", * family = "Shinra", role = "ctb", * email = "rufus@shinrainc.com", comment = list("ORCID-ID" = "902348-439034") ) ``` --- # Adding an author with desc ```r desc::desc_add_author( given = "Rufus", family = "Shinra", role = "ctb", email = "rufus@shinrainc.com", * comment = list("ORCID-ID" = "902348-439034") ) ``` --- # Adding an author with desc ```r desc::desc_add_author( given = "Rufus", family = "Shinra", * role = "ctb", email = "rufus@shinrainc.com", comment = list("ORCID-ID" = "902348-439034") ) ``` --- # R package roles | Code| Role| |--:|--:| | cre | Maintainer | | aut | Author | | ctb | Contributer | | cph | Copyright-holder | Full list: http://www.loc.gov/marc/relators/relaterm.html --- ## Your Turn 2 #### Add a new author to `avalanchr` using `desc::desc_add_author()`. Set `given` to "Barret", `family` to "Wallace", and `role` to "aut". #### In DESCRIPTION, change the title to "Tools for the Avalanche Data Science Team" #### Change the Description field to "A set of tools to use within the Avalance Data Science team. This package contains functions for connecting to data bases, R markdown templates, ggplot2 themes, and more." #### Run `use_tidy_description()` to clean up the file. --- <img src="img/description_license.png" width="100%" height="100%" style="display: block; margin: auto;" /> --- # `use_*_licence()` -- ## **`use_mit_license("Company Name")`**. Check the help page for more. --- # `use_*_licence()` ## ~~`use_mit_license("Company Name")`. Check the help page for more.~~ ## Help with open-source licenses: https://choosealicense.com/ ## Help with proprietary licenses: http://www.binpress.com/license-generator/ --- ## Proprietary licenses ### *Put this in your `DESCRIPTION` file:* ``` License: file LICENSE ``` -- <br><br> ### *Put this in your `LICENSE` file:* ``` Proprietary Do not distribute outside of Shinra, Inc. ``` <br><br> -- ### See also ["Copyright in Closed-Source R Packages: The Right Way"](https://unconj.ca/blog/copyright-in-closed-source-r-packages-the-right-way.html) --- ## Your Turn 3 ## Run `use_mit_license("AVALANCHE")`. What changed? --- ## Your Turn 3: Stretch Goal ## Add "AVALANCHE" as an author with the role of copyright holder. ## Change the license to use the proprietary license above. --- <img src="img/description_vers.png" width="100%" height="100%" style="display: block; margin: auto;" /> --- <img src="img/description_misc1.png" width="100%" height="100%" style="display: block; margin: auto;" /> --- <img src="img/description_misc2.png" width="100%" height="100%" style="display: block; margin: auto;" /> --- # Setting up git and GitHub --- # Setting up git and GitHub ## **`use_git()`**, **`use_github()`** --- # Setting up git and GitHub ## ~~`use_git()`, `use_github()`~~ ## **`create_from_github()`** to clone --- # Setting up git and GitHub ## ~~`use_git()`, `use_github()`~~ ## ~~`create_from_github()` to clone~~ ## **`pr_init()` and friends** to do pull requests --- # Setting up git and GitHub ## ~~`use_git()`, `use_github()`~~ ## ~~`create_from_github()` to clone~~ ## ~~`pr_init()` and friends to do pull requests~~ ## Other usethis functions for setting up GitHub, e.g. labels, issues, contributing guidelines, etc