How to Contribute Code
Source:CONTRIBUTING.md
👍🎉 Hello and a warm welcome to guidelines for contributing code! 🎉👍
Thanks for taking the time to read these guidelines. This helps keep this code repository easy to maintain and the code easy to follow. These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request.
Install Software
Via the “Cloud” - Quick and Easy!
- Go to https://github.com/aquaMetrics/rict and click ‘fork’ in top right.
- Sign-up to R Studio Cloud.
- Click on New Project dropdown menu and select ‘New Project from Git repo’.
- Paste
https://github.com/YOUR-GITHUB-USERNAME/rict
. - replaceYOUR-GITHUB-USERNAME
or navigate to the forked repo you on your profile and copy paste URL. - Next install package dependencies. In the Console panel type:
install.packages("devtools")
thendevtools::install_dev_deps()
then enter1
to install latest versions. - You can now make changes to the files - look in the ‘Files’ tab and look for ‘R’ folder where most R code is held.
- Add
browser()
to the line above where you wish to add a breakpoint in the code/function. - In the Build tab select ‘Install and Build’.
- Now run the function, try typing in the console:
rict(observed_demo_values)
- this will run most functions in the package. - The code will break where you added the
browser()
and you can investigate the values and see what needs changing etc. - Make changes as required then ‘Install and Restart’.
- Once you are happy with the code, go to ‘Commit’ section below. Note, if you have updated documentation, run
pkgdown::build_site()
in the console, this will update package website when your changes are merged: https://aquametrics.github.io/rict/.
Commit
- This step is only needed on your first commit, select the Terminal panel (in lower left) type:
git config --global user.email "your.email@address.co.uk"
git config --global user.name "YOUR_GITHUB_USERNAME"
(changing the email and username to match your own) - In the ‘Git’ panel (top-right) commit select all the files you changed and click commit.
- Add a commit message (which if applicable, includes the reference to the issue number e.g. ‘docs: closes #1’- the ‘#1’ is the issue number)
- Not sure how to write a commit message? Try to use this commit message guidance, although this is not enforced.
- Select ‘Push’ changes.
Create Pull Request
- On your github profile page select the forked rict repo. This will now include the recent changes you made.
- Near the top there is an option to create pull request (PR).
- Select create pull request and enter message reference issue number ‘#1’ that it fixes.
- The PR will be submitted and testing automatically run.
- Wait for response from maintainers.
Deploying
Github actions will automatically update and deploy all changes to the package, docs and web app as long as automated tests pass:
- After, your PR is merged to master branch, automatic tests and builds will be run in “the cloud”.
- These tests check the code for any problems and compatibility by running on Windows, Linux and Mac.
- On the README document (displayed on the repo in github) are the ‘build’ badge icons - these indicate that all tests are running correctly in the cloud.
- The first build badge: links to the Github actions page
- Click this icon to see more details of the automated testing.
Notes on Coding Style & Testing
- Add comments as required to explain the why rather than the how.
- Not every line needs comments - but any large or unusual sections.
- R Package guidance is a very useful resource for writing packages.
- Linting / styling code is not enforced but easy to do.
- Install styler package.
- Run styler to from ‘Addins’ menu.
- Testing allows check coding ‘style’ with rules from lintr package.
- But linting/style is not enforced (so failures are okay but not desired).
- Document code and follow standard CRAN checks and file structure
devtools::check()
. - Run tests locally - before commit
devtools::test()
. - See .lintr file for exact linting rules applied during testing.