Skip to content

Commit 1cb61a0

Browse files
committed
renamed zip and enumerate
1 parent e980c36 commit 1cb61a0

File tree

11 files changed

+90
-52
lines changed

11 files changed

+90
-52
lines changed

NAMESPACE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export(createMutator)
1111
export(divide)
1212
export(enclose)
1313
export(encloseBr)
14-
export(enumerate)
14+
export(enumerateit)
1515
export(findMissingRdSections)
1616
export(fmrs)
1717
export(getAvgHex)
@@ -60,7 +60,7 @@ export(trySplit)
6060
export(val)
6161
export(val1)
6262
export(warningp)
63-
export(zip)
63+
export(zipit)
6464
exportPattern("^[[:alpha:]]+")
6565
importFrom(Rcpp,evalCpp)
6666
importFrom(magrittr,"%>%")

R/iteration.R

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
#' Zip Multiple Vectors or Lists
22
#'
33
#' This function combines multiple vectors or lists element-wise into a list of lists.
4+
#' A slightly lighter weight alternative to `itertools::izip()`
45
#'
56
#' @param ... Vectors or lists to be combined.
67
#'
78
#' @return A list of lists, where each inner list contains the elements from the corresponding positions in the input vectors or lists.
89
#' @export
910
#' @keywords iteration
11+
#' @seealso [enumerateit()]
1012
#' @examples
1113
#' # Zip two vectors
12-
#' zip(c(1, 2, 3), c("a", "b", "c"))
14+
#' zipit(c(1, 2, 3), c("a", "b", "c"))
1315
#' # Zip three vectors
14-
#' zip(c(1, 2), c("x", "y"), c(TRUE, FALSE))
15-
zip <- function(...) mapply(list, ..., SIMPLIFY = FALSE)
16+
#' zipit(c(1, 2), c("x", "y"), c(TRUE, FALSE))
17+
zipit <- function(...) mapply(list, ..., SIMPLIFY = FALSE)
1618

1719
#' Enumerate Elements with Indices
1820
#'
1921
#' This function pairs elements of vectors or lists with their indices. The output
2022
#' is meant to be used in a for loop, and each element extracted with the
21-
#' [ind()], [val()], or [val1()] functions.
23+
#' [ind()], [val()], or [val1()] functions. A slightly lighter weight alternative
24+
#' to `itertools::enumerate()`
2225
#'
2326
#' @param ... Vectors or lists to be enumerated.
2427
#' @param zero_indexed A logical indicating whether indexing should start from zero. Default is FALSE.
@@ -31,13 +34,13 @@ zip <- function(...) mapply(list, ..., SIMPLIFY = FALSE)
3134
#'
3235
#' @examples
3336
#' # Enumerate a vector
34-
#' enumerate(c("a", "b", "c"))
37+
#' enumerateit(c("a", "b", "c"))
3538
#' # Enumerate a vector starting from zero
36-
#' enumerate(c("a", "b", "c"), zero_indexed = TRUE)
39+
#' enumerateit(c("a", "b", "c"), zero_indexed = TRUE)
3740
#' # Enumerate two vectors
38-
#' enumerate(c(1, 2), c("x", "y"))
39-
enumerate <- function(..., zero_indexed = FALSE) {
40-
zip(seq_along(..1) - zero_indexed, ...)
41+
#' enumerateit(c(1, 2), c("x", "y"))
42+
enumerateit <- function(..., zero_indexed = FALSE) {
43+
zipit(seq_along(..1) - zero_indexed, ...)
4144
}
4245

4346
#' Get Index from Enumerated Element
@@ -49,6 +52,7 @@ enumerate <- function(..., zero_indexed = FALSE) {
4952
#' @return The index of the enumerated element.
5053
#' @export
5154
#' @keywords iteration
55+
#' @seealso [enumerateit()]
5256
#' @examples
5357
#' # Extract index from an enumerated element
5458
#' elem <- list(1, "a")
@@ -65,6 +69,7 @@ ind <- function(elem) elem[[1]]
6569
#' @return The value at the specified index in the enumerated element.
6670
#' @export
6771
#' @keywords iteration
72+
#' @seealso [enumerateit()]
6873
#' @examples
6974
#' # Extract value from an enumerated element by index
7075
#' elem <- list(1, "a", "b")
@@ -80,6 +85,7 @@ val <- function(elem, index) elem[[index + 1]]
8085
#' @return The first value in the enumerated element.
8186
#' @export
8287
#' @keywords iteration
88+
#' @seealso [enumerateit()]
8389
#' @examples
8490
#' # Extract the first value from an enumerated element
8591
#' elem <- list(1, "a", "b")

R/math.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
#' @param num A numeric vector to be bounded.
66
#' @param lowerbound The lower bound of the range.
77
#' @param upperbound The upper bound of the range.
8-
#'
8+
#'
99
#' @return A numeric vector with elements bounded within the specified range.
1010
#' @export
1111
#' @keywords math
12-
#'
12+
#'
1313
#' @examples
1414
#' bound(1, 0, 2)
1515
#' bound(1:10, -1, 5)
16-
#'
16+
#'
1717
bound <- function(num, lowerbound, upperbound) {
1818
sapply(num, function(x) min(max(x, lowerbound), upperbound))
1919
}

R/packageLoading.R

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#' @export
3535
#' @keywords packageLoading
3636
#'
37-
installAndLoad <- function(cran = NULL, bioc = NULL, gh = NULL) {
37+
installAndLoad <- function(cran = NULL, bioc = NULL, gh = NULL, lib = .libPaths()[1], verbose = FALSE) {
3838

3939
if (is.null(cran) && is.null(bioc) && is.null(gh)) {
4040
message("no packages inputted")
@@ -44,44 +44,56 @@ installAndLoad <- function(cran = NULL, bioc = NULL, gh = NULL) {
4444
# Load required libraries for installation
4545
if (!is.null(bioc))
4646
if (!requireNamespace("BiocManager", quietly = TRUE))
47-
utils::install.packages("BiocManager")
47+
utils::install.packages("BiocManager", lib = lib)
4848

4949
if (!is.null(gh))
5050
if (!requireNamespace("devtools", quietly = TRUE))
51-
utils::install.packages("devtools")
51+
utils::install.packages("devtools", lib = lib)
5252

5353
# Helper function to install and load a package
54-
install_and_load <- function(packagepath) {
54+
install_and_load <- function(packagepath, source) {
5555

5656
if (is.null(packagepath)) return()
5757

58-
# github packages must be prioritized
58+
# github packages must be prioritized to account for naming conventions
5959
if (source == "GitHub") {
6060
package <- strsplit(packagepath, "/")[[1]][2]
61-
devtools::install_github(
62-
packagepath, force = FALSE, quiet = TRUE, dependencies = TRUE
63-
)
64-
library(package, character.only = TRUE)
65-
return()
61+
62+
} else {
63+
package <- packagepath
6664
}
67-
68-
package <- packagepath
6965

70-
if (!require(package, character.only = TRUE, quietly = TRUE)) {
66+
if (require(package, character.only = TRUE, quietly = TRUE)) return()
7167

72-
if (source == "CRAN") {
73-
utils::install.packages(package, dependencies = TRUE)
74-
} else if (source == "Bioconductor") {
75-
BiocManager::install(package)
76-
}
68+
if (source == "CRAN") {
69+
utils::install.packages(
70+
package,
71+
dependencies = TRUE,
72+
lib = lib
73+
)
74+
} else if (source == "Bioconductor") {
75+
BiocManager::install(
76+
package,
77+
lib = lib,
78+
dependencies = TRUE
79+
)
80+
} else {
81+
warning("* installing `", package, "` from a raw GitHub repository")
82+
devtools::install_github(
83+
packagepath,
84+
force = FALSE,
85+
quiet = TRUE,
86+
dependencies = TRUE,
87+
lib = lib
88+
)
7789
}
7890

7991
library(package, character.only = TRUE)
8092
}
8193

82-
for (el in zip(c("CRAN", "Bioconductor", "GitHub"), c(cran, bioc, gh))) {
83-
for (pkg in el[[2]]) {
84-
suppressPackageStartupMessages(install_and_load(pkg, el[[1]]))
85-
}
94+
for (el in zipi(list("CRAN", "Bioconductor", "GitHub"), list(cran, bioc, gh))) {
95+
sapply(el[[2]], function(pkg) capture.output(suppressMessages((install_and_load(pkg, el[[1]])))))
8696
}
97+
98+
return()
8799
}

man/enumerate.Rd renamed to man/enumerateit.Rd

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/ind.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/installAndLoad.Rd

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/val.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/val1.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/zip.Rd renamed to man/zipit.Rd

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)