Skip to content

Commit

Permalink
version 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
rcannood authored and cran-robot committed Feb 4, 2019
1 parent 31b205d commit 184ef67
Show file tree
Hide file tree
Showing 29 changed files with 1,358 additions and 206 deletions.
25 changes: 14 additions & 11 deletions DESCRIPTION
@@ -1,7 +1,7 @@
Package: dynutils
Type: Package
Title: Common Functionality for the 'dynverse' Packages
Version: 1.0.0
Version: 1.0.1
Authors@R: c(
person(
"Robrecht",
Expand All @@ -21,25 +21,28 @@ Authors@R: c(
Description:
Provides common functionality for the 'dynverse' packages.
'dynverse' is created to support the development, execution, and benchmarking of trajectory inference methods.
For more information, check out <https://github.com/dynverse/dynverse>.
For more information, check out <dynverse.org>.
License: GPL-3
URL: http://github.com/dynverse/dynutils
BugReports: https://github.com/dynverse/dynutils/issues
LazyData: TRUE
RoxygenNote: 6.0.1
RoxygenNote: 6.1.0
Depends: R (>= 3.0.0)
Imports: crayon, devtools, desc, dplyr, glue, magrittr, methods,
processx, purrr, Rcpp, stringr, testthat, tibble, tidyr
Imports: assertthat, crayon, devtools, desc, dplyr, glue, magrittr,
methods, purrr, Rcpp, stringr, testthat, tibble, tidyr
Suggests: ggplot2, knitr, readr, rmarkdown
LinkingTo: Rcpp
VignetteBuilder: knitr
Collate: 'RcppExports.R' 'add_class.R' 'inherit_default_params.R'
'calculate_distance.R' 'check_packages.R' 'expand_matrix.R'
'extend_with.R' 'install_packages.R' 'mapdf.R' 'package.R'
'pritt.R' 'random_time_string.R' 'scaling.R' 'tibble.R'
Collate: 'RcppExports.R' 'add_class.R' 'assertions.R'
'inherit_default_params.R' 'calculate_distance.R'
'check_packages.R' 'expand_matrix.R' 'extend_with.R'
'install_packages.R' 'mapdf.R' 'package.R' 'pritt.R'
'random_time_string.R' 'safe_tempdir.R' 'scaling.R' 'tibble.R'
NeedsCompilation: yes
Packaged: 2018-07-18 12:41:55 UTC; rcannood
Packaged: 2019-02-04 13:48:40 UTC; rcannood
Author: Robrecht Cannoodt [aut, cre] (<https://orcid.org/0000-0003-3641-729X>,
rcannood),
Wouter Saelens [aut] (<https://orcid.org/0000-0002-7114-6248>, zouter)
Maintainer: Robrecht Cannoodt <rcannood@gmail.com>
Repository: CRAN
Date/Publication: 2018-07-18 13:10:09 UTC
Date/Publication: 2019-02-04 14:33:21 UTC
47 changes: 28 additions & 19 deletions MD5
@@ -1,42 +1,49 @@
608cf24991008f2856a87421858392aa *DESCRIPTION
8aca8bbc89cc03f8c11d846303914aa7 *NAMESPACE
e52d4f82a9879aefcee6d7fa9e3932ce *DESCRIPTION
4da048babd5735b0684fa46451c77a3f *NAMESPACE
15b3317475a4dc79ee837baf020b4210 *R/RcppExports.R
6f7fc8ddd74f0326bf2b59a523681cf7 *R/add_class.R
a6959673a8f23837866ad8629a424263 *R/assertions.R
e3850008f88dd058ab181e539a5c50d6 *R/calculate_distance.R
d12293c4bf7b1a545afd8a8772ef9160 *R/check_packages.R
ebced609202a59d493b476c3aac3fe8d *R/expand_matrix.R
85c44df9d66d900d3faffeda2bdb4cbf *R/extend_with.R
7b04594ee09c9b479b8ac5bd1863546e *R/inherit_default_params.R
d3bdc879cc8de54ca1297fde2536702b *R/install_packages.R
aaabb9fde3b05e2ed4a51753235b6157 *R/mapdf.R
3255589fcaed67404498fb0983713ab5 *R/package.R
e13cf8e863091bbccce7aff6232179bd *R/install_packages.R
3d1b74d29cd7cee98c0e149d0f718aa0 *R/mapdf.R
3a9553e3fd55f7cf2a75d778f6c69297 *R/package.R
15faad85abe90be3921dcaa156de86bd *R/pritt.R
37bf34c1b1fb077abcc7cb9156a84f38 *R/random_time_string.R
d441cad116ada35f3ad9fb934cc96485 *R/safe_tempdir.R
f8dd8af76a7ac011a43271821a80d626 *R/scaling.R
c57520019a9bd779737ce37dbd3e5451 *R/tibble.R
0914edf25fcf8d667015bf5c6d2ec43b *README.md
d4d8b29b95540d27d4550c4896a1d62d *build/vignette.rds
8207888e7b8d50bd61ed53aeaa43c008 *inst/NEWS
552e6e0c1e70efca10b3db1994bc4786 *inst/doc/functionality.R
59e4d8087b619be25f5a83fd1846e261 *inst/doc/functionality.Rmd
d4d77130edd4c4694254a000e806d296 *inst/doc/functionality.html
1a382f59e99865b7c0941c3fbddf5218 *R/tibble.R
71487f4c49ceee79c978c2c54a9db7fd *README.md
3bee9bf2edeafb3a833b4e20407e5590 *build/vignette.rds
2e7dc4c9258f1e3aaaf4888778393605 *inst/NEWS
af96c567fd536cf2c9c8d92f9d6372fc *inst/doc/functionality.R
128af78003634650e1cae7471dce91fd *inst/doc/functionality.Rmd
48ce047e292c36f0a5c03aa1df0c404f *inst/doc/functionality.html
c3db2b03d9fad3aa6837b3f565dfdebd *man/add_class.Rd
a33c27d2e9586ef8137b228d3d34c6e7 *man/all_in.Rd
b5ac523861808607b014847cb3797765 *man/apply_minmax_scale.Rd
64174b3e65b65ce84ce3293ae492f994 *man/apply_quantile_scale.Rd
3bef0a231eef2816e0a263a1e4a2242c *man/apply_uniform_scale.Rd
6771faace1ff701049356a61c23bad7e *man/calculate_distance.Rd
3252699f0111548d1c5865b259fc6045 *man/check_packages.Rd
413271f77bb57611aeb016fa8f4d5e85 *man/dynutils.Rd
d2d2982d64bc291341f9815289319dbb *man/dynutils.Rd
7709555d2461d3fdc0754ff9ed78c279 *man/expand_matrix.Rd
3018e1eb12824f76075b195fe12a4916 *man/extend_with.Rd
9aaed213184b39633d36df275e873813 *man/extract_row_to_list.Rd
7613b5995b078d708cc26c1a5d2d9b88 *man/extract_row_to_list.Rd
21c38d6edb23eb7766127edfb805d2cc *man/has_names.Rd
740e7a7bf33786b1c8cefcf8ded17610 *man/inherit_default_params.Rd
92547389f18931a8166951634e019577 *man/install_packages.Rd
ffb5cc4ea8eb2cc74b8881ee03793acc *man/is_bounded.Rd
b9518d93e55a498b29be70221d67e209 *man/is_single_numeric.Rd
c75c1e1f49dbefd8590f7424587ad69b *man/list_as_tibble.Rd
aaa833eaa967c4031572cff9760ea88a *man/mapdf.Rd
8cd7a90e9d50cd5f8fe1c8b8d1731d73 *man/mapdf.Rd
62bd4790a9a678a2922a0b80a60ed606 *man/pritt.Rd
d030ba9674691137199ba8be588b2986 *man/project_to_segments.Rd
2cf7693dbaf3302c64209d7336c447d5 *man/random_time_string.Rd
4709d575d5fa06a874efac612a29ee78 *man/safe_tempdir.Rd
3ebf0627b766e627129d9ea56bc4e725 *man/scale_minmax.Rd
796b56abcd3919f503ddecb80735ea9a *man/scale_quantile.Rd
f9110f58085b0ae3ca4bc37b1bec76c9 *man/scale_uniform.Rd
Expand All @@ -46,16 +53,18 @@ c44a23e08f260ed4006b531a0eecc561 *src/calculate_distance.cpp
fa89e1f21fd5ca27ac892f4ba8ba9c7c *src/project_to_segments.cpp
645f970b5add7df4c3623df1e9c09778 *tests/testthat.R
90070d56ee12b1460c344b2a4dd11d46 *tests/testthat/test-add_class.R
35e9b56c7825d520e904f7fefc4bc561 *tests/testthat/test-assertions.R
1d3471e3c4f0726a5a3cf2f65a33e807 *tests/testthat/test-calculate_distance.R
dbb99d66a04da64c942eeb3d2aad76a4 *tests/testthat/test-check_packages.R
7485242237d66f602ee1126cbe4000c2 *tests/testthat/test-expand_matrix.R
8faa7d5a28c69f65e45e8ff451fc705b *tests/testthat/test-extend_with.R
5ce31da95e0ab2cae64f31550e6957c1 *tests/testthat/test-inherit_default_params.R
d993460d1ce3623f3edcff631b8f5b9f *tests/testthat/test-install_packages.R
756bcdea5c45ef09d977a958b55c2695 *tests/testthat/test-mapdf.R
5a0b8841cae5fd25cd22193bb97735b3 *tests/testthat/test-install_packages.R
ddab0c82ed76e18043f565728e5d9743 *tests/testthat/test-mapdf.R
d1f8057d6b406af20752b9a0a963107a *tests/testthat/test-pritt.R
12b22a50c13f031e04cafada2045e5eb *tests/testthat/test-project_to_segments.R
15ff28feffad09aff3b062301884d6a4 *tests/testthat/test-random_time_string.R
1dd87c9774930551ff14571b16e3a407 *tests/testthat/test-safe_tempdir.R
bacf3a9c91b28b7ab6ff90784e38ee69 *tests/testthat/test-scaling.R
14eb963310f7d37419f201073a91a6ed *tests/testthat/test-tibble.R
59e4d8087b619be25f5a83fd1846e261 *vignettes/functionality.Rmd
fc042589bc13e4175521bb1d10631436 *tests/testthat/test-tibble.R
128af78003634650e1cae7471dce91fd *vignettes/functionality.Rmd
12 changes: 12 additions & 0 deletions NAMESPACE
@@ -1,6 +1,9 @@
# Generated by roxygen2: do not edit by hand

export("%all_in%")
export("%has_names%")
export(add_class)
export(all_in)
export(apply_minmax_scale)
export(apply_quantile_scale)
export(apply_uniform_scale)
Expand All @@ -11,8 +14,11 @@ export(euclidean_distance)
export(expand_matrix)
export(extend_with)
export(extract_row_to_list)
export(has_names)
export(inherit_default_params)
export(install_packages)
export(is_bounded)
export(is_single_numeric)
export(list_as_tibble)
export(manhattan_distance)
export(mapdf)
Expand All @@ -21,10 +27,12 @@ export(mapdf_dbl)
export(mapdf_dfc)
export(mapdf_dfr)
export(mapdf_int)
export(mapdf_lat)
export(mapdf_lgl)
export(pritt)
export(project_to_segments)
export(random_time_string)
export(safe_tempdir)
export(scale_minmax)
export(scale_quantile)
export(scale_uniform)
Expand All @@ -35,6 +43,9 @@ import(methods)
import(stringr)
import(tibble)
import(tidyr)
importFrom(Rcpp,evalCpp)
importFrom(assertthat,"%has_name%")
importFrom(assertthat,"on_failure<-")
importFrom(desc,desc_get_remotes)
importFrom(devtools,install_cran)
importFrom(devtools,install_github)
Expand All @@ -44,6 +55,7 @@ importFrom(magrittr,"%<>%")
importFrom(magrittr,set_colnames)
importFrom(magrittr,set_rownames)
importFrom(purrr,"%>%")
importFrom(purrr,"%||%")
importFrom(purrr,as_mapper)
importFrom(purrr,discard)
importFrom(purrr,keep)
Expand Down
191 changes: 191 additions & 0 deletions R/assertions.R
@@ -0,0 +1,191 @@
#' Check whether a value is a single numeric
#'
#' @param x A value to be tested
#'
#' @export
#'
#' @examples
#' \dontrun{
#' library(assertthat)
#' assert_that(is_single_numeric(1))
#' # TRUE
#'
#' assert_that(is_single_numeric(Inf))
#' # TRUE
#'
#' assert_that(is_single_numeric(1.6))
#' # TRUE
#'
#' assert_that(is_single_numeric(NA))
#' # Error: NA is not a single numeric value
#'
#' assert_that(is_single_numeric(1:6))
#' # Error: 1:6 is not a single numeric value
#'
#' assert_that(is_single_numeric("pie"))
#' # Error: "pie" is not a single numeric value
#' }
is_single_numeric <- function(x) {
length(x) == 1 && is.numeric(x) && !is.na(x)
}
on_failure(is_single_numeric) <- function(call, env) {
paste0(deparse(call$x), " is not a single numeric value")
}

#' Check whether a value within a certain interval
#'
#' @param x A value to be tested
#' @param lower_bound The lower bound
#' @param lower_closed Whether the lower bound is closed
#' @param upper_bound The upper bound
#' @param upper_closed Whether the upper bound is closed
#'
#' @export
#'
#' @examples
#' \dontrun{
#' library(assertthat)
#' assert_that(is_bounded(10))
#' # TRUE
#'
#' assert_that(is_bounded(10:30))
#' # TRUE
#'
#' assert_that(is_bounded(Inf))
#' # Error: Inf is not bounded by (-Inf,Inf)
#'
#' assert_that(is_bounded(10, lower_bound = 20))
#' # Error: 10 is not bounded by (20,Inf)
#'
#' assert_that(is_bounded(
#' 10,
#' lower_bound = 20,
#' lower_closed = TRUE,
#' upper_bound = 30,
#' upper_closed = FALSE
#' ))
#' # Error: 10 is not bounded by [20,30)
#' }
is_bounded <- function(x, lower_bound = -Inf, lower_closed = FALSE, upper_bound = Inf, upper_closed = FALSE) {
all(
is.numeric(x) & !is.na(x) &
{if (lower_closed) lower_bound <= x else lower_bound < x} &
{if (upper_closed) x <= upper_bound else x < upper_bound}
)
}
on_failure(is_bounded) <- function(call, env) {
left_sym <- if (eval(call$lower_closed) %||% formals(is_bounded)$lower_closed) "[" else "("
right_sym <- if (eval(call$upper_closed) %||% formals(is_bounded)$upper_closed) "]" else ")"
left_bound <- eval(call$lower_bound) %||% eval(formals(is_bounded)$lower_bound)
right_bound <- eval(call$upper_bound) %||% eval(formals(is_bounded)$upper_bound)
paste0(deparse(call$x), " is not bounded by ", left_sym, left_bound, ",", right_bound, right_sym)
}

#' Check whether an object has certain names
#'
#' @param x object to test
#' @param which name
#'
#' @export
#' @importFrom assertthat %has_name%
#'
#' @examples
#' \dontrun{
#' library(assertthat)
#' li <- list(a = 1, b = 2)
#'
#' assert_that(li %has_names% "a")
#' # TRUE
#'
#' assert_that(li %has_names% "c")
#' # Error: li is missing 1 name from "c": "c"
#'
#' assert_that(li %has_names% letters)
#' # Error: li is missing 24 names from letters: "c", "d", "e", ...
#' }
has_names <- function(x, which) {
all(x %has_name% which)
}
on_failure(has_names) <- function(call, env) {
paste0(deparse(call$x), " does not have names ", deparse(setdiff(eval(call$which, env), names(eval(call$x, env)))))
}
on_failure(has_names) <- function(call, env) {
x <- names(eval(call$x, env))
which <- eval(call$which, env)
elements <- setdiff(which, x)
elem_str <-
elements %>%
head(3) %>%
map_chr(deparse) %>%
paste(collapse = ", ")

paste0(
deparse(call$x),
" is missing ",
length(elements),
" name",
ifelse(length(elements) == 1, "", "s"),
" from ",
deparse(call$which),
": ",
elem_str,
ifelse(length(elements) > 3, ", ...", "")
)
}

#' @rdname has_names
#' @export
`%has_names%` <- has_names

#' Check whether a vector are all elements of another vector
#'
#' @param x The values to be matched.
#' @param table The values to be matched against.
#'
#' @export
#'
#' @examples
#' \dontrun{
#' library(assertthat)
#' assert_that(c(1, 2) %all_in% c(0, 1, 2, 3, 4))
#' # TRUE
#'
#' assert_that("a" %all_in% letters)
#' # TRUE
#'
#' assert_that("A" %all_in% letters)
#' # Error: "A" is missing 1 element from letters: "A"
#'
#' assert_that(1:10 %all_in% letters)
#' # Error: 1:10 is missing 10 elements from letters: 1, 2, 3, ...
#' }
all_in <- function(x, table) {
all(x %in% table)
}
on_failure(all_in) <- function(call, env) {
x <- eval(call$x, env)
table <- eval(call$table, env)
elements <- setdiff(x, table)
elem_str <-
elements %>%
head(3) %>%
map_chr(deparse) %>%
paste(collapse = ", ")

paste0(
deparse(call$x),
" is missing ",
length(elements),
" element",
ifelse(length(elements) == 1, "", "s"),
" from ",
deparse(call$table),
": ",
elem_str,
ifelse(length(elements) > 3, ", ...", "")
)
}

#' @rdname all_in
#' @export
`%all_in%` <- all_in
2 changes: 1 addition & 1 deletion R/install_packages.R
Expand Up @@ -28,7 +28,7 @@ install_packages <- function(..., package = NULL, prompt = FALSE) {
if (prompt) {
message(paste0(
"Following packages have to be installed: ",
glue::collapse(crayon::bold(dependencies), ", ", last = " and ")
glue::glue_collapse(crayon::bold(dependencies), ", ", last = " and ")
))
answer <- ifelse (
is.null(getOption("dynutils_testmodepromptresponse")),
Expand Down

0 comments on commit 184ef67

Please sign in to comment.