6 Conclusion
Tutorial: Good Software Engineering Practice for R Packages
July 8, 2024
R package structure
- R package = folder structure with (many) conventions
- With modern tools
usethis
, roxygen2
it is easy to start a new package
- Packaging a set of functions is an ideal way to share with collaborators and the public
- Start small and simple and over time you can learn additional options
Engineering Workflow
- Use a workable workflow:
Idea \(\rightarrow\) Design docs \(\rightarrow\) Programming \(\rightarrow\) Quality check \(\rightarrow\) Publication
- Don’t waste time on maintenance
- Be faster with release on CRAN
- Fulfill quality requirements of yourself and stakeholders
- Refactor your one-off scripts that you want to use in a package
- Use assertions for all arguments \(\rightarrow\) better user experience
- Implement common generics like
print
and plot
Ensuring Quality
- Apply common clean code rules, e.g.,
- Use testthat to test, test, and test
- Use covr to improve the test coverage
- Use styler to optimize the code styling
- Don’t repeat yourself!
- Your rewards are:
- Maintainability,
- Extensibility, and
- Performance!
Publication
pkgdown
can help you easily create a nice website for your package
- Versions and licenses along with
NEWS
updates are important
- GitHub helps with tagging of release versions
- R-Hub helps with checking before CRAN submission
Thank you!
- It was great to teach you today on how to build R packages
- Let’s keep in touch e.g. via the gitter chat channel for this course that you can connect to
- We welcome feedback on topics/format/content - reach out!
Possible next steps
- Bring the information back to your colleagues in your organization
- Start building your first own package and share internally first
- Later publish it open source on GitHub and submit it to CRAN
- Learn about more tips and tricks how to extend R
Photo by Pixabay on pexels.com