Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6ee7acf
Showing
50 changed files
with
1,933 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
Package: dynutils | ||
Type: Package | ||
Title: Common Functions for the Dynverse Packages | ||
Version: 0.1.0 | ||
Authors@R: c( | ||
person( | ||
"Robrecht", | ||
"Cannoodt", | ||
email = "rcannood@gmail.com", | ||
role = c("aut", "cre"), | ||
comment = c(ORCID = "0000-0003-3641-729X", github = "rcannood") | ||
), | ||
person( | ||
"Wouter", | ||
"Saelens", | ||
email = "wouter.saelens@ugent.be", | ||
role = c("aut"), | ||
comment = c(ORCID = "0000-0002-7114-6248", github = "zouter") | ||
) | ||
) | ||
Description: | ||
Provides a common functionality for the dynverse packages. | ||
Dynverse is created to support the development, execution, and benchmarking of trajectory inference methods. | ||
For more information, see <https://github.com/dynverse/dynverse>. | ||
License: GPL-3 | ||
LazyData: TRUE | ||
RoxygenNote: 6.0.1 | ||
Depends: R (>= 3.0.0) | ||
Imports: crayon, devtools, desc, dplyr, glue, magrittr, methods, | ||
processx, purrr, Rcpp, stringr, testthat, tibble, tidyr | ||
LinkingTo: Rcpp | ||
Collate: 'RcppExports.R' 'add_class.R' 'inherit_default_params.R' | ||
'calculate_distance.R' 'expand_matrix.R' 'extend_with.R' | ||
'install_packages.R' 'package.R' 'pritt.R' | ||
'random_time_string.R' 'run_until_exit.R' 'scaling.R' | ||
'tibble.R' | ||
NeedsCompilation: yes | ||
Packaged: 2018-06-24 12:41:04 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-06-24 14:07:55 UTC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
160299d0627fd1b4937e2e8180938520 *DESCRIPTION | ||
7fd1cd0ad39b2c648625195a33d2a7cb *NAMESPACE | ||
559e9bffb8bf1e8f6fa2bee69eb30f4e *R/RcppExports.R | ||
30b96236f20a33e753cd9e30df10a17d *R/add_class.R | ||
e3850008f88dd058ab181e539a5c50d6 *R/calculate_distance.R | ||
0f487a73cab63061f96224412030a45e *R/expand_matrix.R | ||
9a35a257fed55e02d97c629a50add7ad *R/extend_with.R | ||
1799b09d5fd7efef74826bfc3f941e1b *R/inherit_default_params.R | ||
07154a189a5cb37288feb45a608f9a53 *R/install_packages.R | ||
804c2119fd58eebf877dc70df4c2ef30 *R/package.R | ||
2caaac611f00a3c04d56ea872171f578 *R/pritt.R | ||
28910897cf6c132d3244396d44c3cf29 *R/random_time_string.R | ||
286706fca7f4e4d3fff835a740c429e3 *R/run_until_exit.R | ||
9cb7cbe0086cfb38c03c9873305f1913 *R/scaling.R | ||
550683d4b4e4c47e74ebcf7538ff0f94 *R/tibble.R | ||
8b370792756e494e0cec32034d7b3e8b *README.md | ||
3d00986de3d8d541714a7dd58f3a2ce0 *man/add_class.Rd | ||
b5ac523861808607b014847cb3797765 *man/apply_minmax_scale.Rd | ||
64174b3e65b65ce84ce3293ae492f994 *man/apply_quantile_scale.Rd | ||
3bef0a231eef2816e0a263a1e4a2242c *man/apply_uniform_scale.Rd | ||
6771faace1ff701049356a61c23bad7e *man/calculate_distance.Rd | ||
bca985c7d6c2e02cd94152865c08f9aa *man/check_packages.Rd | ||
09abf5e13b450bc468bdb12786252548 *man/dynutils.Rd | ||
bdef8b65413518dfe3eb5198f56999cc *man/expand_matrix.Rd | ||
39511ee494f98c86ef0c814408a895f2 *man/extend_with.Rd | ||
5f8774f6b38947d6cd9342c01d6d0d9a *man/extract_row_to_list.Rd | ||
477a87afa99a1d7fab80ad6de6bad480 *man/inherit_default_params.Rd | ||
705111d76df76b2dee7e84ac28436829 *man/install_packages.Rd | ||
cdcecfb50415bd66de2de57fc0859613 *man/list_as_tibble.Rd | ||
78ae11d4f9fd66d62a142b48a0c2d4e7 *man/pritt.Rd | ||
7fdcbd475956fbd310599893c985d802 *man/random_time_string.Rd | ||
e40429d5ea63f5668a626fe44b3158ad *man/run_until_exit.Rd | ||
ab9f5a1c1ab3a0848d9d8aba7b32e7fa *man/scale_minmax.Rd | ||
2d96623cf5d66cd92fb5505d58373356 *man/scale_quantile.Rd | ||
42596f98342158554f6e89171e3a5df2 *man/scale_uniform.Rd | ||
674deaa0bac0516c48694763b0db986b *src/RcppExports.cpp | ||
c44a23e08f260ed4006b531a0eecc561 *src/calculate_distance.cpp | ||
645f970b5add7df4c3623df1e9c09778 *tests/testthat.R | ||
90070d56ee12b1460c344b2a4dd11d46 *tests/testthat/test-add_class.R | ||
88e6091b676fd212af7b8092ac5b00a2 *tests/testthat/test-calculate_distance.R | ||
7485242237d66f602ee1126cbe4000c2 *tests/testthat/test-expand_matrix.R | ||
8faa7d5a28c69f65e45e8ff451fc705b *tests/testthat/test-extend_with.R | ||
5ce31da95e0ab2cae64f31550e6957c1 *tests/testthat/test-inherit_default_params.R | ||
8877b963ff0ac63ef9d85918d715ce49 *tests/testthat/test-install_packages.R | ||
d1f8057d6b406af20752b9a0a963107a *tests/testthat/test-pritt.R | ||
15ff28feffad09aff3b062301884d6a4 *tests/testthat/test-random_time_string.R | ||
e74119145832bd5f34f17638ef62070b *tests/testthat/test-run_until_exit.R | ||
bacf3a9c91b28b7ab6ff90784e38ee69 *tests/testthat/test-scaling.R | ||
e8f3614bd73b1b86237c96d5ae9888ac *tests/testthat/test-tibble.R |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(add_class) | ||
export(apply_minmax_scale) | ||
export(apply_quantile_scale) | ||
export(apply_uniform_scale) | ||
export(calculate_distance) | ||
export(check_packages) | ||
export(correlation_distance) | ||
export(euclidean_distance) | ||
export(expand_matrix) | ||
export(extend_with) | ||
export(extract_row_to_list) | ||
export(inherit_default_params) | ||
export(install_packages) | ||
export(list_as_tibble) | ||
export(manhattan_distance) | ||
export(pritt) | ||
export(random_time_string) | ||
export(run_until_exit) | ||
export(scale_minmax) | ||
export(scale_quantile) | ||
export(scale_uniform) | ||
import(dplyr) | ||
import(methods) | ||
import(stringr) | ||
import(tibble) | ||
import(tidyr) | ||
importFrom(desc,desc_get_remotes) | ||
importFrom(devtools,install_cran) | ||
importFrom(devtools,install_github) | ||
importFrom(glue,glue) | ||
importFrom(magrittr,"%$%") | ||
importFrom(magrittr,"%<>%") | ||
importFrom(magrittr,set_colnames) | ||
importFrom(magrittr,set_rownames) | ||
importFrom(purrr,"%>%") | ||
importFrom(purrr,keep) | ||
importFrom(purrr,map) | ||
importFrom(purrr,map_chr) | ||
importFrom(purrr,map_dbl) | ||
importFrom(purrr,map_df) | ||
importFrom(purrr,map_int) | ||
importFrom(purrr,map_lgl) | ||
importFrom(purrr,set_names) | ||
importFrom(stats,cor) | ||
importFrom(stats,quantile) | ||
importFrom(stats,setNames) | ||
importFrom(testthat,expect_equal) | ||
importFrom(testthat,expect_is) | ||
importFrom(testthat,expect_named) | ||
importFrom(utils,installed.packages) | ||
importFrom(utils,setRepositories) | ||
useDynLib(dynutils) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Generated by using Rcpp::compileAttributes() -> do not edit by hand | ||
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 | ||
|
||
manhattan_distance <- function(x, y) { | ||
.Call('_dynutils_manhattan_distance', PACKAGE = 'dynutils', x, y) | ||
} | ||
|
||
euclidean_distance <- function(x, y) { | ||
.Call('_dynutils_euclidean_distance', PACKAGE = 'dynutils', x, y) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#' Add class to object whilst keeping the old classes | ||
#' | ||
#' @inheritParams base::class | ||
#' @param class A character vector naming classes | ||
#' | ||
#' @export | ||
add_class <- function(x, class) { | ||
class(x) <- c(class, class(x)) | ||
x | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#' @importFrom testthat expect_is | ||
calculate_distance_preproc_x <- function(x) { | ||
testthat::expect_is(x, c("matrix", "data.frame", "dgCMatrix")) | ||
as.matrix(x) | ||
} | ||
|
||
#' @importFrom testthat expect_equal | ||
calculate_distance_preproc_y <- function(x, y) { | ||
if (is.null(y)) y <- x | ||
testthat::expect_equal(ncol(y), ncol(x)) | ||
calculate_distance_preproc_x(y) | ||
} | ||
|
||
calculate_distance_postproc_d <- function(x, y, d) { | ||
dimnames(d) <- list(rownames(x), rownames(y)) | ||
d | ||
} | ||
|
||
#' Distance metrics | ||
#' | ||
#' Calculate (pairwise) distances between two matrices | ||
#' | ||
#' @param x A numeric matrix | ||
#' @param y (Optional) a numeric matrix, with \code{ncol(x) == ncol(y)}. | ||
#' @param method Distance method to use. Options are: | ||
#' \itemize{ | ||
#' \item euclidean: \code{\link{euclidean_distance}} | ||
#' \item manhattan: \code{\link{manhattan_distance}} | ||
#' \item spearman, pearson, or kendall: \code{\link{correlation_distance}} | ||
#' } | ||
#' | ||
#' @rdname calculate_distance | ||
#' | ||
#' @export | ||
#' | ||
#' @examples | ||
#' ## Generate two matrices with 50 and 100 samples | ||
#' x <- matrix(rnorm(50*10, mean = 0, sd = 1), ncol = 10) | ||
#' y <- matrix(rnorm(100*10, mean = 1, sd = 2), ncol = 10) | ||
#' | ||
#' dist_euclidean <- calculate_distance(x, y, method = "euclidean") | ||
#' dist_manhattan <- calculate_distance(x, y, method = "manhattan") | ||
#' dist_spearman <- calculate_distance(x, y, method = "spearman") | ||
#' dist_pearson <- calculate_distance(x, y, method = "pearson") | ||
#' dist_kendall <- calculate_distance(x, y, method = "kendall") | ||
calculate_distance <- function( | ||
x, | ||
y = NULL, | ||
method = c("euclidean", "manhattan", "spearman", "pearson", "kendall") | ||
) { | ||
method <- match.arg(method) | ||
|
||
if (method == "euclidean") { | ||
euclidean_distance(x, y) | ||
} else if (method == "manhattan") { | ||
manhattan_distance(x, y) | ||
} else if (method %in% c("spearman", "pearson", "kendall")) { | ||
correlation_distance(x, y, method = method) | ||
} | ||
} | ||
|
||
#' @rdname calculate_distance | ||
#' | ||
#' @inheritParams stats::cor | ||
#' | ||
#' @importFrom stats cor | ||
#' | ||
#' @include inherit_default_params.R | ||
#' | ||
#' @export | ||
correlation_distance <- inherit_default_params( | ||
list(stats::cor), | ||
function(x, y, method, use) { | ||
x <- calculate_distance_preproc_x(x) | ||
y <- calculate_distance_preproc_y(x, y) | ||
|
||
d <- 1 - (stats::cor(t(x), t(y), method = method, use = use) + 1) / 2 | ||
|
||
calculate_distance_postproc_d(x, y, d) | ||
} | ||
) | ||
|
||
#' @rdname calculate_distance | ||
#' | ||
#' @export | ||
manhattan_distance <- function(x, y = NULL) { | ||
x <- calculate_distance_preproc_x(x) | ||
y <- calculate_distance_preproc_y(x, y) | ||
|
||
d <- .Call('_dynutils_manhattan_distance', PACKAGE = 'dynutils', x, y) | ||
|
||
calculate_distance_postproc_d(x, y, d) | ||
} | ||
|
||
#' @rdname calculate_distance | ||
#' | ||
#' @export | ||
euclidean_distance <- function(x, y = NULL) { | ||
x <- calculate_distance_preproc_x(x) | ||
y <- calculate_distance_preproc_y(x, y) | ||
|
||
d <- .Call('_dynutils_euclidean_distance', PACKAGE = 'dynutils', x, y) | ||
|
||
calculate_distance_postproc_d(x, y, d) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#' Expand a matrix with given rownames and colnames | ||
#' | ||
#' @param mat The matrix to expand | ||
#' @param rownames The desired rownames | ||
#' @param colnames The desired colnames | ||
#' @param fill With what to fill missing data | ||
#' | ||
#' @export | ||
expand_matrix <- function( | ||
mat, | ||
rownames = NULL, | ||
colnames = NULL, | ||
fill = 0 | ||
) { | ||
if (is.null(rownames)) { | ||
rownames <- rownames(mat) | ||
} | ||
if (is.null(colnames)) { | ||
colnames <- colnames(mat) | ||
} | ||
newmat <- matrix( | ||
fill, | ||
nrow = length(rownames), | ||
ncol = length(colnames), | ||
dimnames = list(rownames, colnames) | ||
) | ||
newmat[rownames(mat),colnames(mat)] <- mat | ||
newmat | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#' Extend an object | ||
#' | ||
#' @param object A list | ||
#' @param .class_name A class name to add | ||
#' @param ... Extra information in the list | ||
#' | ||
#' @importFrom testthat expect_is expect_named | ||
#' | ||
#' @export | ||
extend_with <- function( | ||
object, | ||
.class_name, | ||
... | ||
) { | ||
testthat::expect_is(object, "list") | ||
testthat::expect_is(.class_name, "character") | ||
|
||
extension <- list(...) | ||
|
||
if (is.null(names(extension)) && length(extension) == 1 && "list" %in% class(extension[[1]])) { | ||
extension <- extension[[1]] | ||
} | ||
|
||
testthat::expect_is(extension, "list") | ||
testthat::expect_named(extension) | ||
testthat::expect_false(any(names(extension) == "")) | ||
|
||
object[names(extension)] <- extension | ||
|
||
add_class(object, .class_name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#' Inherit default parameters from a list of super functions | ||
#' | ||
#' @param super_functions A list of super functions of which \code{fun} needs to inherit the default parameters | ||
#' @param fun The function whose default parameters need to be overridden | ||
#' | ||
#' @return Function \code{fun}, but with the default parameters of the \code{super_functions} | ||
#' @export | ||
#' | ||
#' @examples | ||
#' fun1 <- function(a = 10, b = 7) { | ||
#' runif(a, -b, b) | ||
#' } | ||
#' | ||
#' fun2 <- function(c = 9) { | ||
#' 2^c | ||
#' } | ||
#' | ||
#' fun3 <- inherit_default_params( | ||
#' super = list(fun1, fun2), | ||
#' fun = function(a, b, c) { | ||
#' x <- fun1(a, b) | ||
#' y <- fun2(c) | ||
#' list(x = x, y = y) | ||
#' } | ||
#' ) | ||
#' | ||
#' fun3(1, 2, 3) | ||
#' fun3() | ||
inherit_default_params <- function(super_functions, fun) { | ||
if (is.function(super_functions)) { | ||
super_functions <- list(super_functions) | ||
} | ||
for (sup in super_functions) { | ||
argsup <- intersect(formalArgs(fun), formalArgs(sup)) | ||
formals(fun)[argsup] <- formals(sup)[argsup] | ||
} | ||
fun | ||
} |
Oops, something went wrong.