forked from LebeerLab/tidytacos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.R
47 lines (40 loc) · 1.22 KB
/
utils.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#' Create a tidytacos object for testing/example purporses
#'
#' @return a small tidytacos object
#'
#' @export
test_taco <- function() {
# Initiate abundance matrix
x <- matrix(
c(1500, 1300, 280, 356, 456, 678),
ncol = 3
)
rownames(x) <- c("taxon1", "taxon2")
colnames(x) <- c("sample1", "sample2", "sample3")
# Convert to tidytacos object
data <- create_tidytacos(x,
taxa_are_columns = FALSE
)
data
}
#' Removes empty samples from the tidytacos object
#'
#' @param ta a tidytacos object
#' @return the tidytacos object minus the empty samples
#'
#' @export
remove_empty_samples <- function(ta){
present_samples <- ta %>% counts() %>%
dplyr::group_by(sample_id) %>%
dplyr::count() %>% pull(sample_id)
empty_samples <- ta$samples$sample_id[!(ta$samples$sample_id %in% present_samples)]
ta <- ta %>% filter_samples(!sample_id %in% empty_samples)
ta
}
# Checks if optional dependency is loaded and stops code if not.
force_optional_dependency <- function(optional_pkg, instructions=NULL){
if (!requireNamespace(optional_pkg, quietly = TRUE)) {
stop(paste("The", optional_pkg, "package must be installed to use this function.", instructions))
}
NULL
}