assertive.sets/0000755000176200001440000000000013031524405013231 5ustar liggesusersassertive.sets/po/0000755000176200001440000000000013031226356013653 5ustar liggesusersassertive.sets/po/R-assertive.sets.pot0000644000176200001440000000120013031226356017551 0ustar liggesusersmsgid "" msgstr "" "Project-Id-Version: assertive.sets 0.0-1\n" "Report-Msgid-Bugs-To:https://bitbucket.org/richierocks/assertive.sets\n" "POT-Creation-Date: 2015-08-13 09:39\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: Richard Cotton \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" msgid "%s and %s have different numbers of elements (%d versus %d)." msgstr "" msgid "The element %s in %s is not in %s." msgid_plural "The elements %s in %s are not in %s." msgstr[0] "" msgstr[1] "" assertive.sets/tests/0000755000176200001440000000000013031226356014377 5ustar liggesusersassertive.sets/tests/testthat.R0000644000176200001440000000011013031226356016352 0ustar liggesuserslibrary(testthat) library(assertive.sets) test_check("assertive.sets") assertive.sets/tests/testthat/0000755000176200001440000000000013031524405016233 5ustar liggesusersassertive.sets/tests/testthat/test-is-set.R0000644000176200001440000000576513031255502020553 0ustar liggesuserstest_that( "test are_disjoint_sets with disjoint sets returns true", { x <- 1:5 y <- 6:10 expect_true(are_disjoint_sets(x, y)) } ) test_that( "test are_disjoint_sets with intersecting sets returns false", { x <- 1:5 expect_false(actual <- are_disjoint_sets(x, 4:8)) expect_match( cause(actual), noquote("x and 4:8 have common elements: 4, 5") ) } ) test_that( "test are_intersecting_sets with intersecting sets returns true", { x <- 1:5 y <- 5:9 expect_true(are_intersecting_sets(x, y)) } ) test_that( "test are_intersecting_sets with disjoint sets returns false", { x <- 1:5 expect_false(actual <- are_intersecting_sets(x, 6:10)) expect_match( cause(actual), noquote("x and 6:10 have no common elements") ) } ) test_that( "test are_set_equal with equal sets returns true", { x <- 1:5 y <- c(1, 3, 5, 4, 2) expect_true(are_set_equal(x, y)) } ) test_that( "test are_set_equal with different size sets returns false", { x <- 1:5 y <- c(1:4, 4) expect_false(actual <- are_set_equal(x, y)) expect_match( cause(actual), "1:5 and c\\(1, 2, 3, 4\\) have different numbers of elements \\(5 versus 4\\)" ) } ) test_that( "test are_set_equal with unequal sets returns false", { x <- 1:5 y <- c(99, 3, 5, 4, 2) expect_false(actual <- are_set_equal(x, y)) # R is doing something odd with references to variable names, so the # cause isn't "The element '1' in x is not in y." # Using force() doesn't seem to make a difference. expect_match( cause(actual), noquote("The element .+1.+ in 1:5 is not in c\\(99, 3, 5, 4, 2\\)") ) } ) test_that( "test is_subset with equal sets returns true", { x <- 1:5 expect_true(is_subset(x, x)) } ) test_that( "test is_subset with equal sets and strictly = TRUE returns false", { x <- 1:5 expect_false(is_subset(x, x, strictly = TRUE)) } ) test_that( "test is_subset with a subset returns true", { x <- 1:5 y <- 6:1 expect_true(is_subset(x, y)) } ) test_that( "test is_subset with a non-subset returns false", { x <- 1:5 y <- 4:1 expect_false(actual <- is_subset(x, y)) expect_match( cause(actual), noquote("The element .+5.+ in x is not in y") ) } ) test_that( "test is_superset with equal sets returns true", { x <- 1:5 expect_true(is_superset(x, x)) } ) test_that( "test is_superset with equal sets and strictly = TRUE returns false", { x <- 1:5 expect_false(is_superset(x, x, strictly = TRUE)) } ) test_that( "test is_superset with a superset returns true", { x <- 1:6 y <- 5:1 expect_true(is_superset(x, y)) } ) test_that( "test is_superset with a non-superset returns false", { x <- 1:4 y <- 5:1 expect_false(actual <- is_superset(x, y)) expect_match( cause(actual), "The element .+5.+ in y is not in x" ) } ) assertive.sets/NAMESPACE0000644000176200001440000000100313031226356014446 0ustar liggesusers# Generated by roxygen2: do not edit by hand export(are_disjoint_sets) export(are_intersecting_sets) export(are_set_equal) export(assert_are_disjoint_sets) export(assert_are_intersecting_sets) export(assert_are_set_equal) export(assert_is_set_equal) export(assert_is_subset) export(assert_is_superset) export(is_set_equal) export(is_subset) export(is_superset) importFrom(assertive.base,assert_engine) importFrom(assertive.base,cause) importFrom(assertive.base,false) importFrom(assertive.base,get_name_in_parent) assertive.sets/NEWS0000644000176200001440000000045513031226356013740 0ustar liggesusers0.0-3 Added are_disjoint_sets, are_intersecting_sets. Removed withr dependency. 0.0-2 is_set_equal renamed as are_set_equal. is_subset and is_superset gain a "strictly" argument. Use of devtools in tests replaced with withr. 0.0-1 Content extracted from assertive 0.3-0, and tidied. assertive.sets/R/0000755000176200001440000000000013031226356013436 5ustar liggesusersassertive.sets/R/is-set.R0000644000176200001440000001053613031226356014772 0ustar liggesusers#' @rdname are_set_equal #' @export are_disjoint_sets <- function(x, y, .xname = get_name_in_parent(x), .yname = get_name_in_parent(y)) { intersectionxy <- intersect(x, y) if(length(intersectionxy) > 0) { return( false( gettext( "%s and %s have common elements: %s." ), .xname, .yname, toString(intersectionxy, width = 100) ) ) } TRUE } #' @rdname are_set_equal #' @export are_intersecting_sets <- function(x, y, .xname = get_name_in_parent(x), .yname = get_name_in_parent(y)) { intersectionxy <- intersect(x, y) if(length(intersectionxy) == 0) { return( false( gettext( "%s and %s have no common elements." ), .xname, .yname ) ) } TRUE } #' Set comparisons #' #' Checks on the contents of two vectors (ignoring the order of the elements). #' @param x A vector. #' @param y Another vector. #' @param strictly Logical. If \code{TRUE}, \code{x} and \code{y} should not #' be set equal. #' @param .xname Not intended to be used directly. #' @param .yname Not intended to be used directly. #' @param severity How severe should the consequences of the assertion be? #' Either \code{"stop"}, \code{"warning"}, \code{"message"}, or \code{"none"}. #' @return The \code{is_*} functions return \code{TRUE} or \code{FALSE}. #' The \code{assert_*} functions throw an error in the event of failure. #' @seealso \code{\link[base]{sets}}, \code{\link[sets]{set_is_equal}} #' @examples #' # Same contents, different order, returns TRUE #' are_set_equal(1:5, 5:1) #' #' # Different lengths #' are_set_equal(1:5, 1:6) #' #' # First vector contains values not in second vector #' are_set_equal(1:5, c(1:4, 4)) #' #' # Second vector contains values not in first vector #' are_set_equal(c(1:4, 4), 1:5) #' #' # Is x a subset of y? #' is_subset(1:4, 1:5) #' is_subset(1:5, 1:4) #' #' # Is x a superset of y? #' is_superset(1:5, 1:4) #' is_superset(1:4, 1:5) #' #' # The strictly argument checks for a strict sub/superset #' is_subset(1:5, 1:5, strictly = TRUE) #' is_superset(1:5, 1:5, strictly = TRUE) #' #' # Do x and y have common elements? #' are_intersecting_sets(1:4, 3:6) #' are_disjoint_sets(1:4, 3:6) #' #' # Types are coerced to be the same, as per base::setdiff #' are_set_equal(1:4, c("4", "3", "2", "1")) #' #' # Errors are thrown in the event of failure #' assert_are_set_equal(1:5, 5:1) #' assertive.base::dont_stop(assert_are_set_equal(1:5, 1:6)) #' #' assert_is_subset(1:4, 1:5) #' assertive.base::dont_stop(assert_is_subset(1:5, 1:4)) #' #' assert_is_superset(1:5, 1:4) #' assertive.base::dont_stop(assert_is_superset(1:4, 1:5)) #' #' # A common use case: checking that data contains required columns #' required_cols <- c("Time", "weight", "Diet") #' assert_is_superset(colnames(ChickWeight), required_cols) #' @export are_set_equal <- function(x, y, .xname = get_name_in_parent(x), .yname = get_name_in_parent(y)) { x <- unique(x) y <- unique(y) if(length(x) != length(y)) { return( false( gettext( "%s and %s have different numbers of elements (%d versus %d)." ), .xname, .yname, length(x), length(y) ) ) } if(!(ok <- is_subset(x, y, FALSE, .xname, .yname))) { return(ok) } if(!(ok <- is_subset(y, x, FALSE, .yname, .xname))) { return(ok) } TRUE } #' @rdname are_set_equal #' @export is_set_equal <- function(x, y, .xname = get_name_in_parent(x), .yname = get_name_in_parent(y)) { .Deprecated("are_set_equal") are_set_equal(x, y, .xname, .yname) } #' @rdname are_set_equal #' @export is_subset <- function(x, y, strictly = FALSE, .xname = get_name_in_parent(x), .yname = get_name_in_parent(y)) { diffxy <- setdiff(x, y) if(length(diffxy) > 0) { return( false( ngettext( length(diffxy), "The element %s in %s is not in %s.", "The elements %s in %s are not in %s." ), toString(sQuote(diffxy), width = 100), .xname, .yname ) ) } if(strictly && length(setdiff(y, x)) == 0) { return(false("%s and %s are set equal.", .xname, .yname)) } TRUE } #' @rdname are_set_equal #' @export is_superset <- function(x, y, strictly = FALSE, .xname = get_name_in_parent(x), .yname = get_name_in_parent(y)) { is_subset(y, x, strictly, .yname, .xname) } assertive.sets/R/assert-is-set.R0000644000176200001440000000337413031226356016273 0ustar liggesusers#' @rdname are_set_equal #' @export assert_are_disjoint_sets <- function(x, y, severity = getOption("assertive.severity", "stop")) { assert_engine( are_disjoint_sets, x, y = y, .xname = get_name_in_parent(x), .yname = get_name_in_parent(y), severity = severity ) } #' @rdname are_set_equal #' @export assert_are_intersecting_sets <- function(x, y, severity = getOption("assertive.severity", "stop")) { assert_engine( are_intersecting_sets, x, y = y, .xname = get_name_in_parent(x), .yname = get_name_in_parent(y), severity = severity ) } #' @rdname are_set_equal #' @export assert_are_set_equal <- function(x, y, severity = getOption("assertive.severity", "stop")) { assert_engine( are_set_equal, x, y = y, .xname = get_name_in_parent(x), .yname = get_name_in_parent(y), severity = severity ) } #' @rdname are_set_equal #' @export assert_is_set_equal <- function(x, y, severity = getOption("assertive.severity", "stop")) { .Deprecated("assert_are_set_equal") assert_are_set_equal(x, y, severity = severity) } #' @rdname are_set_equal #' @export assert_is_subset <- function(x, y, strictly = FALSE, severity = getOption("assertive.severity", "stop")) { assert_engine( is_subset, x, y = y, strictly = strictly, .xname = get_name_in_parent(x), .yname = get_name_in_parent(y), severity = severity ) } #' @rdname are_set_equal #' @export assert_is_superset <- function(x, y, strictly = FALSE, severity = getOption("assertive.severity", "stop")) { assert_engine( is_superset, x, y = y, strictly = strictly, .xname = get_name_in_parent(x), .yname = get_name_in_parent(y), severity = severity ) } assertive.sets/R/imports.R0000644000176200001440000000025213031226356015255 0ustar liggesusers#' @importFrom assertive.base assert_engine #' @importFrom assertive.base false #' @importFrom assertive.base get_name_in_parent #' @importFrom assertive.base cause NULL assertive.sets/README.md0000644000176200001440000000306713031226356014522 0ustar liggesusers[![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/0.1.0/active.svg)](http://www.repostatus.org/#active) [![Is the package on CRAN?](http://www.r-pkg.org/badges/version/assertive.sets)](http://www.r-pkg.org/pkg/assertive.sets) [![SemaphoreCI Build Status](https://semaphoreci.com/api/v1/projects/8f9d4316-ca97-419c-9a71-eed37e9b3165/635160/badge.svg)](https://semaphoreci.com/richierocks/assertive-sets) [![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/2d3nr6mxrbhiubxq?svg=true)](https://ci.appveyor.com/project/richierocks/assertive-sets) # assertive.sets A set of predicates and assertions for checking the properties of sets. Most of the documentation is on the *[assertive](https://bitbucket.org/richierocks/assertive)* page. End-users will usually want to use *assertive* directly. ### Installation To install the stable version, type: ```{r} install.packages("assertive.sets") ``` To install the development version, you first need the *devtools* package. ```{r} install.packages("devtools") ``` Then you can install the *assertive.sets* package using ```{r} library(devtools) install_bitbucket("richierocks/assertive.sets") ``` ### Predicates `is_set_equal` checks if two vectors contain the same elements (maybe in different orders). `is_subset` and `is_superset` check if one set is contained in another. ### Assertions Predicates all return a single logical value and have one corresponding assertion. For example, `is_subset` has `assert_is_subset`.assertive.sets/MD50000644000176200001440000000103713031524405013542 0ustar liggesusersd42dc737203f727943f65e286be12e4f *DESCRIPTION 883f79986c77b4eabe593c6a163977d4 *NAMESPACE 08ed7345e4862075068ee217d3da6d78 *NEWS c1f4a752f1b61d985d3a9294c1723d3f *R/assert-is-set.R cf1a056e7087ed7e667f64d52c92040f *R/imports.R ce97a5f34dcfcc6551044df5775f97d8 *R/is-set.R f3d2dc0675a1aa3334c6e395aedc3a6d *README.md 828dc5a52dcc9d1dd8ca680639a700f6 *man/are_set_equal.Rd 33d959419355a94edb383331b8eef20d *po/R-assertive.sets.pot 1adeabe3e52df46cfcf3adb186c8e23a *tests/testthat.R abe10475a2a97546549165ca4bfc6690 *tests/testthat/test-is-set.R assertive.sets/DESCRIPTION0000644000176200001440000000235513031524405014744 0ustar liggesusersPackage: assertive.sets Type: Package Title: Assertions to Check Properties of Sets Version: 0.0-3 Date: 2016-12-30 Author: Richard Cotton [aut, cre] Maintainer: Richard Cotton Authors@R: person("Richard", "Cotton", role = c("aut", "cre"), email = "richierocks@gmail.com") Description: A set of predicates and assertions for checking the properties of sets. This is mainly for use by other package developers who want to include run-time testing features in their own packages. End-users will usually want to use assertive directly. URL: https://bitbucket.org/richierocks/assertive.sets BugReports: https://bitbucket.org/richierocks/assertive.sets/issues Depends: R (>= 3.0.0) Imports: assertive.base (>= 0.0-7) Suggests: testthat License: GPL (>= 3) LazyLoad: yes LazyData: yes Acknowledgments: Development of this package was partially funded by the Proteomics Core at Weill Cornell Medical College in Qatar . The Core is supported by 'Biomedical Research Program' funds, a program funded by Qatar Foundation. RoxygenNote: 5.0.1 NeedsCompilation: no Packaged: 2016-12-30 18:02:45 UTC; richierocks Repository: CRAN Date/Publication: 2016-12-30 19:35:49 assertive.sets/man/0000755000176200001440000000000013031251516014004 5ustar liggesusersassertive.sets/man/are_set_equal.Rd0000644000176200001440000000667313031251516017120 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/assert-is-set.R, R/is-set.R \name{assert_are_disjoint_sets} \alias{are_disjoint_sets} \alias{are_intersecting_sets} \alias{are_set_equal} \alias{assert_are_disjoint_sets} \alias{assert_are_intersecting_sets} \alias{assert_are_set_equal} \alias{assert_is_set_equal} \alias{assert_is_subset} \alias{assert_is_superset} \alias{is_set_equal} \alias{is_subset} \alias{is_superset} \title{Set comparisons} \usage{ assert_are_disjoint_sets(x, y, severity = getOption("assertive.severity", "stop")) assert_are_intersecting_sets(x, y, severity = getOption("assertive.severity", "stop")) assert_are_set_equal(x, y, severity = getOption("assertive.severity", "stop")) assert_is_set_equal(x, y, severity = getOption("assertive.severity", "stop")) assert_is_subset(x, y, strictly = FALSE, severity = getOption("assertive.severity", "stop")) assert_is_superset(x, y, strictly = FALSE, severity = getOption("assertive.severity", "stop")) are_disjoint_sets(x, y, .xname = get_name_in_parent(x), .yname = get_name_in_parent(y)) are_intersecting_sets(x, y, .xname = get_name_in_parent(x), .yname = get_name_in_parent(y)) are_set_equal(x, y, .xname = get_name_in_parent(x), .yname = get_name_in_parent(y)) is_set_equal(x, y, .xname = get_name_in_parent(x), .yname = get_name_in_parent(y)) is_subset(x, y, strictly = FALSE, .xname = get_name_in_parent(x), .yname = get_name_in_parent(y)) is_superset(x, y, strictly = FALSE, .xname = get_name_in_parent(x), .yname = get_name_in_parent(y)) } \arguments{ \item{x}{A vector.} \item{y}{Another vector.} \item{severity}{How severe should the consequences of the assertion be? Either \code{"stop"}, \code{"warning"}, \code{"message"}, or \code{"none"}.} \item{strictly}{Logical. If \code{TRUE}, \code{x} and \code{y} should not be set equal.} \item{.xname}{Not intended to be used directly.} \item{.yname}{Not intended to be used directly.} } \value{ The \code{is_*} functions return \code{TRUE} or \code{FALSE}. The \code{assert_*} functions throw an error in the event of failure. } \description{ Checks on the contents of two vectors (ignoring the order of the elements). } \examples{ # Same contents, different order, returns TRUE are_set_equal(1:5, 5:1) # Different lengths are_set_equal(1:5, 1:6) # First vector contains values not in second vector are_set_equal(1:5, c(1:4, 4)) # Second vector contains values not in first vector are_set_equal(c(1:4, 4), 1:5) # Is x a subset of y? is_subset(1:4, 1:5) is_subset(1:5, 1:4) # Is x a superset of y? is_superset(1:5, 1:4) is_superset(1:4, 1:5) # The strictly argument checks for a strict sub/superset is_subset(1:5, 1:5, strictly = TRUE) is_superset(1:5, 1:5, strictly = TRUE) # Do x and y have common elements? are_intersecting_sets(1:4, 3:6) are_disjoint_sets(1:4, 3:6) # Types are coerced to be the same, as per base::setdiff are_set_equal(1:4, c("4", "3", "2", "1")) # Errors are thrown in the event of failure assert_are_set_equal(1:5, 5:1) assertive.base::dont_stop(assert_are_set_equal(1:5, 1:6)) assert_is_subset(1:4, 1:5) assertive.base::dont_stop(assert_is_subset(1:5, 1:4)) assert_is_superset(1:5, 1:4) assertive.base::dont_stop(assert_is_superset(1:4, 1:5)) # A common use case: checking that data contains required columns required_cols <- c("Time", "weight", "Diet") assert_is_superset(colnames(ChickWeight), required_cols) } \seealso{ \code{\link[base]{sets}}, \code{\link[sets]{set_is_equal}} }