We welcome human contributions to metacheck (we do not accept pull requests with a bot or agent as a named contributor). Small bug fixes can be made as a simple pull request, but contributing a new built-in module or function to the package needs to follow the guidance below.
- Intro to R Packages for a quick focused intro
- R Packages for all the details
Contributorship model
We will acknowledge substantial contributions to code (e.g., contribution of a new module) as contributors (“ctb” role) in the DESCRIPTION. Smaller bug fixes may be acknowledged in the NEWS.md file. An authorship (“aut” role) may be earned by sustained major contributions of code or intellectual input to the project.
Adding a new built-in module
Metacheck is meant to be modular and for users to be able to buil their own libraries of modules that are most relevant to their purposes. If you have an idea for a new module that you think most users of metacheck would benefit from, we encourage you to reach out to use at metacheck@scienceverse.org first to discuss. If you have been invited to contribute a modeule, please follow the steps below.,
-
test_that("module_name", { module <- "module_name" mods <- module_list() expect_true(module %in% mods$name) paper <- demopaper() expect_no_error( mo <- module_run(paper, module) ) }) -
# sample 10 random papers papers <- sample(psychsci, 10) # generate a report for each paper reports <- report(papers, "module_name") browseURL(reports) # metascience workflow mod_output <- module_run(paper, "module_name")
Unit Tests
I use test-driven development, so I write the unit test below for any new function before I even start to write the function. Then I never forget to document it.
test_that("newfunc", {
expect_true(is.function(metacheck::newfunc))
expect_no_error(helplist <- help(newfunc, metacheck))
expect_error(newfunc(bad_arg))
})
A test should give at least one basic example showing the most typical use of the function. Every time you realise the function doesn’t behave exactly as you expect, write a failing test for that example and work on the code until it’s not failing anymore.
Helper files
If you need to define functions for your tests, put the functions in tests/testthat/helper.R.
If you need to provide test files (e.g., JSON for a paper that shows a specific thing), put them under tests/testthat/fixtures/.
Mocking
If your test requires external resources, once the tests are passing, capture them using the third mock argument to our custom version of test_that(). (This is a workaround for the fact that httptest2 doesn’t mock parallel httr2 requests, so don’t use the httptest2 functions directly.) This will save files to tests/testthat/apis/ to mock the response without needing a web connection.
test_that("describe", {
# code
}, mock = "capture")After you’ve captured the response, change the value to “mock” and check that the test still passes. It should be much faster and not require an internet connection. If the function includes a call to online() to check the status of the resource, you will need to locally mock this function as below.
testthat::local_mocked_bindings(
online = \(...) TRUE
)