Showing 3 of 5 files from the diff.
Other files ignored by Codecov

@@ -338,3 +338,51 @@
 338 338 ` }` 339 339 ` )` 340 340 `)` 341 + 342 + `#' @name Primes` 343 + `#' @title Set of Prime Numbers` 344 + `#' @description The mathematical set of prime numbers,` 345 + `#' defined as the the set of integers that are divisible only be one and themselves.` 346 + `#' @family special sets` 347 + `#' @export` 348 + `Primes <- R6Class("Primes",` 349 + ` inherit = SpecialSet,` 350 + ` public = list(` 351 + ` #' @description Create a new `Primes` object.` 352 + ` #' @return A new `Primes` object.` 353 + ` initialize = function() {` 354 + ` super\$initialize(lower = 2, type = "[]", class = "integer")` 355 + ` },` 356 + 357 + ` #' @description Tests to see if \code{x} is contained in the Set.` 358 + ` #'` 359 + ` #' @param x any. Object or vector of objects to test.` 360 + ` #' @param all logical. If `FALSE` tests each `x` separately. Otherwise returns `TRUE` only if all `x` pass test.` 361 + ` #' @param bound logical.` 362 + ` #'` 363 + ` #' @details \code{x} can be of any type, including a Set itself. \code{x} should be a tuple if` 364 + ` #' checking to see if it lies within a set of dimension greater than one. To test for multiple \code{x}` 365 + ` #' at the same time, then provide these as a list.` 366 + ` #'` 367 + ` #' If `all = TRUE` then returns `TRUE` if all `x` are contained in the `Set`, otherwise` 368 + ` #' returns a vector of logicals. For [Interval]s, `bound` is used to specify if elements lying on the` 369 + ` #' (possibly open) boundary of the interval are considered contained (`bound = TRUE`) or not (`bound = FALSE`).` 370 + ` #'` 371 + ` #' @return If \code{all} is `TRUE` then returns `TRUE` if all elements of \code{x} are contained in the `Set`, otherwise` 372 + ` #' `FALSE.` If \code{all} is `FALSE` then returns a vector of logicals corresponding to each individual` 373 + ` #' element of \code{x}.` 374 + ` #'` 375 + ` #' The infix operator `%inset%` is available to test if `x` is an element in the `Set`,` 376 + ` #' see examples.` 377 + ` contains = function(x, all = FALSE, bound = NULL) {` 378 + ` l <- vapply(x, checkmate::testIntegerish, logical(1))` 379 + ` x[l] = PrimesContains(x[l])` 380 + ` x[!l] = FALSE` 381 + 382 + ` returner(` 383 + ` x = as.logical(x),` 384 + ` all = all` 385 + ` )` 386 + ` }` 387 + ` )` 388 + `)`

@@ -18,7 +18,8 @@
 18 18 ` posreals = paste0("\u211D", zero_str, "+"),` 19 19 ` negreals = paste0("\u211D", zero_str, "-"),` 20 20 ` extendedreals = "\u211D \u222A {-\u221E, +\u221E}",` 21 - ` complex = "\u2102"` 21 + ` complex = "\u2102",` 22 + ` primes = "\u2118"` 22 23 ` ))` 23 24 ` } else {` 24 25 ` return(switch(set,`
@@ -34,7 +35,8 @@
 34 35 ` posreals = paste0("R", zero_str, "+"),` 35 36 ` negreals = paste0("R", zero_str, "-"),` 36 37 ` extendedreals = "R U {-Inf, +Inf}",` 37 - ` complex = "C"` 38 + ` complex = "C",` 39 + ` primes = "P"` 38 40 ` ))` 39 41 ` }` 40 42 `}`

@@ -42,3 +42,24 @@
 42 42 43 43 ` return true;` 44 44 `}` 45 + 46 + `// [[Rcpp::export]]` 47 + `LogicalVector PrimesContains(IntegerVector x) {` 48 + ` LogicalVector ret(x.size());` 49 + ` for (int i = 0; i < x.size(); i++) {` 50 + ` if (x[i] < 2L) {` 51 + ` ret[i] = false;` 52 + ` } else if (x[i] == 2L) {` 53 + ` ret[i] = true;` 54 + ` } else {` 55 + ` ret[i] = true;` 56 + ` for (int j = 2; j <= ceil(sqrt(x[i])); j++) {` 57 + ` if (x[i] % j == 0) {` 58 + ` ret[i] = false;` 59 + ` break;` 60 + ` }` 61 + ` }` 62 + ` }` 63 + ` }` 64 + ` return ret;` 65 + `}`
Files Coverage
R 98.44%
src/contains.cpp 60.53%
Project Totals (35 files) 97.49%