Skip to contents

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.

Adding a new built-in module

  • 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")

Adding a new function

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/.