Science Score: 36.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
✓Academic publication links
Links to: zenodo.org -
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (13.6%) to scientific vocabulary
Repository
Unit testing for R
Basic Info
- Host: GitHub
- Owner: ravingmantis
- Language: R
- Default Branch: master
- Size: 364 KB
Statistics
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 7
- Releases: 7
Metadata Files
README.md
unittest: Concise, TAP-compliant, R package for writing unit tests
Given a simple function you'd like to test in the file myfunction.R:
biggest <- function(x,y) { max(c(x,y)) }
A test script for this function test_myfunction.R would be:
library(unittest)
source('myfunction.R') # Or library(mypackage) if part of a package
ok(biggest(3,4) == 4, "two numbers")
ok(biggest(c(5,3),c(3,4)) == 5, "two vectors")
You can then run this test in several ways:
source('test_myfunction.R')from RRscript --vanilla test_myfunction.Rfrom the command promptR CMD check, iftest_myfunction.Ris inside thetestsdirectory ofmypackagebeing tested.unittestdoesn't require any further setup in your package.
If writing tests as part of a package, see the "Adding Tests to Packages" vignette for more information.
The workhorse of the unittest package is the ok function which prints "ok" when the expression provided evaluates to TRUE and "not ok" if the expression evaluates to anything else or results in an error.
There are several ut_cmp_* helpers designed to work with ok:
ok(ut_cmp_equal( biggest(1/3, 2/6), 2/6), "two floating point numbers"): Uses all.equal to compare within a tolerance.ok(ut_cmp_identical( biggest("c", "d") ), "two strings"): Uses identical to make sure outputs are identical.ok(ut_cmp_error(biggest(3), '"y".*missing'), "single argument is an error"): Make sure the code produces an error matching the regular expression.
In all cases you get detailed, colourised output on what the difference is, for example:
The package was inspired by Perl's Test::Simple.
If you want more features there are other unit testing packages out there; see testthat, RUnit, svUnit.
Installing from CRAN
In an R session type
install.packages('unittest')
Or add Suggests: unittest to your package's DESCRIPTION file.
Installing the latest development version directly from GitHub
To install the latest development version, use remotes:
# install.packages("remotes")
remotes::install_github("ravingmantis/unittest")
Owner
- Name: ravingmantis
- Login: ravingmantis
- Kind: organization
- Repositories: 2
- Profile: https://github.com/ravingmantis
GitHub Events
Total
Last Year
Committers
Last synced: over 2 years ago
Top Committers
| Name | Commits | |
|---|---|---|
| Jamie Lentin | jm@l****k | 130 |
| Anthony Hennessey | ah@r****m | 19 |
| Jamie Lentin | jm@r****m | 5 |
Committer Domains (Top 20 + Academic)
Dependencies
- R >= 3.0.0 depends
- knitr * suggests
- rmarkdown * suggests
- actions/checkout v3 composite
- actions/upload-artifact main composite
- r-lib/actions/setup-pandoc v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite
- actions/checkout v3 composite
- peaceiris/actions-gh-pages v3 composite
- r-lib/actions/setup-pandoc v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite