class: center, middle, inverse, title-slide # Can you trust your package? 📦 ## PyData Lancaster ### Rhian Davies (
@trianglegirl
) --- layout:true layout: true <div class="jr-header"> <img class="logo" src="assets/white_logo_full.png"/> <span class="social"><table><tr><td><img src="assets/twitter.gif"/></td><td> @jumping_uk</td></tr></table></span> </div> <div class="jr-footer"><span>© 2020 Jumping Rivers (jumpingrivers.com)</span><div></div></div> --- # Jumping Rivers .pull-left[ <img src="assets/robot.jpg"></img> ] .pull-right[ * On-site training (RSS accredited) * R and python consultancy * Dashboard creation * Code review * Continuous integration * RStudio full service certified partners * System architecture * R Package development * Predictive analytics ] --- # Our clients <div id="clients"> <img src="assets/shell.png"></img><img src="assets/sustrans.png"></img> <img src="assets/yorkshire.png"></img><img src="assets/hastings.png"></img> <img src="assets/Pragmatic.png" style=position:relative;top:*2.5rem></img><img src="assets/nhs.png"></img> <img src="assets/royal_statistical_society.jpg"></img><img src="assets/Francis_Crick_Institute.png"></img> <img src="assets/Ministry_of_Defence.png"></img><img src="assets/University_of_Manchester.png"></img> <img src="assets/scot-gov.png"></img> <img src="assets/ea.png" style=position:relative;top:-3rem></img> </div> --- # Hands up... 🙋 * If you've written a package? -- * If you've written a test for your code before? -- * If you've used version control before? -- * If you've used continuous integration before? --- # Git Refresher  --- class: center, middle, inverse  --- class: center, middle, inverse  --- class: center, middle, inverse  --- class: middle center # The Philosophy 🧘 -- ### Make small changes 🐭 -- ### Integrate daily 🔝 -- ### Test automatically 🤖 --- # Why use CI? * Get daily constant feedback 🔁 * Catch bugs early 🐛 * Avoid the monster commit 👹 * You don't have to remember to run `devtools::check()` 🤦 --- # Travis? .pull-left[ * A hosted continuous integration service * Used to build and test software projects hosted at GitHub * Essentially a push to GitHub, triggers another job * This job could be anything ] .pull-right[ <img src="assets/travis.png"></img> ] --- # How to set it up? * Host your R package on GitHub * Create a `.travis.yml` file `usethis::use_travis()` * Go to travis-ci.org to link your GitHub account with travis * Turn on ci for your project by switching the button -- ```r > usethis::use_travis() ✔ Setting active project to '/home/rhian/Documents/presentations/2019-11-16-trust-your-pkg' ✔ Writing '.travis.yml' ✔ Adding '^\\.travis\\.yml$' to '.Rbuildignore' ● Turn on travis for your repo at https://travis-ci.org/profile/trianglegirl ``` --- # An example `travis.yml` file ```{} language: r cache: packages ``` -- ```{} r: - oldrel - release - devel ``` -- ```{} notifications: email: recipients: - alerts@jumpingrivers.support on_success: change on_failure: change ``` --- class: center # What jobs can you run on Travis?     --- # Badge-tastic [](https://travis-ci.org/jr-packages/jrIntroduction) ```{} [](https://travis-ci.org/jr-packages/jrIntroduction) ``` --- # Jumping Rivers and CI * R training notes 📖 * Spell check * Full stops * Up-to-date packages * Dead links * Chapter titles match slide titles * Our R packages 📦 * Standard package check * LintR / Flake8 styling * Sensible file names --- # Note check demo ``` ◉ Comparing to master ◉ Checking template files ◉ Checking package versions ◉ Spell check (experimental) ◉ Checking chapters for title case ◉ Checking section for sentence case ◉ Checking for full stops ◉ Checking for undefined citations ◉ Checking for duplicate labels ◉ Checking for undefined refs ◉ Checking URLS ◉ Checking lint ◉ Checking version in config.yml ◉ Checking for uncommitted ✔ Everything committed! ★ ★ You are fabulous! ★ ★ ``` --- # inteRgrate 📦 * We wanted to **simplify** and **standardise** the way we use CI * Create functions which will work on GitHub, GitLab and in R * Specify the exact number of NOTES and WARNINGS we allow * Automate the checks locally **before** pushing --- # Main functions of inteRgrate ✔️ * `check_pkg()` * `check_r_filenames()` * `check_tidy_description()` * `check_lintr()` * `check_namespace()` ```{} inteRgrate::check_lintr() ◉ Checking lint...check_lintr() ◉ Checking vignettes .......... ✔ Lint looks good ``` --- # What if you're forgetful like me? 🤦 * `inteRgrate::add_pre_commit()` * `inteRgrate::add_pre_push()` ```{} $ git commit -m "Test inteRgrate" ◉ Checking file extensions...check_r_filenames() ✔ Extensions look good ✔ Filenames look good ℹ Checking R/get_data.R /home/rhian/git/jr-packages/jrIntroduction/R/get_data.R:54:4: style: Put spaces around all infix operators. e=new.env() ~^~ Error: ✖ Linting errors Execution halted ``` --- # Package build & test with Python 🐍 ``` run-test: stage: test script: - poetry run pip3 install jrpytests - poetry run python3 -c "import jrpytests; jrpytests.checkvignettespdffiles()" - poetry run python3 -c "import jrpytests; jrpytests.runpytests()" - poetry run python3 -c "import jrpytests; jrpytests.runflake8pythonfiles()" - poetry run python3 -c "import jrpytests; jrpytests.runflake8rmdpychunks()" except: - master run-publish: stage: publish script: - poetry publish --username "__token__" --password "$PYPI_TOKEN" only: - master ``` --- class: center, middle, inverse  --- class: center, middle, inverse  --- class: center, middle, inverse  --- class: center, middle, inverse  --- class: center, middle, inverse  --- class: center, middle, inverse  ---  --- # Summary .pull-left[ * Use continuous integration ✔️ * Don't get upset when it fails 😩 * Feel happy you've taken a step toward more robust code 🔒 * Chat to us if you need help ✉️ #### Resources * [inteRgrate](https://github.com/jumpingrivers/inteRgrate) * [usethis](https://usethis.r-lib.org/) * [tic](https://github.com/ropenscilabs/tic) * [Julia's blogpost](https://juliasilge.com/blog/beginners-guide-to-travis/) * [GitHub PAT](https://itsalocke.com/blog/using-travis-make-sure-you-use-a-github-pat/) ] .pull-right[  ]