Write R package tests with AI
Describe the behaviour a function should preserve and turn it into a repeatable test with controlled fixtures, errors and cleanup.
Write R package tests with AI when you can describe how a function should behave but your current test only checks that it returns something. The r-testthat skill helps an agent choose an expectation that matches the behaviour users rely on. For a report reader, preserving column names may matter just as much as returning the right number of rows.
Start with a small invented table whose answer you can verify by hand. If the function writes a temporary file or calls an external service, decide which part the test actually needs. An isolated fixture can make the result repeatable and keep a failed run from contaminating the next one.
What it does
- Choose expectations for values, structure or an intended error.
- Create a minimal fixture for a normal and an unusual input.
- Keep working-directory or environment changes local to a test.
- Replace permitted external dependencies with controlled test doubles.
- Review changes to recorded output before accepting a new snapshot.
Install and use
- Use a permitted R package with testthat version three or later. Some cleanup patterns also use withr. Test in an authorised project environment.
- Ask, “Test this importer with two rows and a missing-column case. Keep the temporary input file local to the test.”
- Run the focused checks and read failures against the original behavioural contract.
FAQ
Source
Made by Garrick Aden-Buie. Original skill: r-testthat, published on GitHub under the MIT licence.
View on GitHub