-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
60 changed files
with
1,085 additions
and
32 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 |
---|---|---|
|
@@ -5,18 +5,17 @@ Version: 0.1.0 | |
Date: 2024-05-23 | ||
Authors@R: c(person("Qile", "Yang", email = "[email protected]", role = c("cre","aut","cph"))) | ||
Maintainer: Qile Yang <[email protected]> | ||
Description: One paragraph description of what the package does as one | ||
or more full sentences. | ||
Description: for general use. All functions have vectorized implementations whenever possible. | ||
BugReports: https://github.com/Qile0317/FastUtils/issues/ | ||
License: MIT + file LICENSE | ||
Encoding: UTF-8 | ||
Language: en-US | ||
Imports: | ||
data.table, | ||
dplyr, | ||
ggplot2, | ||
hash, | ||
Rcpp (>= 1.0.12) | ||
Rcpp (>= 1.0.12), | ||
usethis | ||
LinkingTo: Rcpp | ||
Suggests: | ||
testthat (>= 3.0.0) | ||
|
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 |
---|---|---|
@@ -1,3 +1,39 @@ | ||
useDynLib(ArrayStats, .registration=TRUE) | ||
importFrom(Rcpp, evalCpp) | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
S3method(getfirst,default) | ||
S3method(getlast,default) | ||
export(add) | ||
export(bound) | ||
export(closestWord) | ||
export(createHash) | ||
export(createMutator) | ||
export(divide) | ||
export(enumerate) | ||
export(getAvgHex) | ||
export(getChar) | ||
export(getUniquePairsUpTo) | ||
export(getfirst) | ||
export(getlast) | ||
export(ind) | ||
export(initEmptyTable) | ||
export(initTestthat) | ||
export(initV) | ||
export(isBound) | ||
export(isEven) | ||
export(isOdd) | ||
export(isVowel) | ||
export(multiply) | ||
export(namedNumericToTable) | ||
export(prependIndefArticle) | ||
export(scaleHex) | ||
export(startsWithVowel) | ||
export(stripSpaces) | ||
export(substrEnd) | ||
export(subtract) | ||
export(tableToNumeric) | ||
export(val) | ||
export(val1) | ||
export(zip) | ||
exportPattern("^[[:alpha:]]+") | ||
importFrom(Rcpp,evalCpp) | ||
useDynLib(FastUtils, .registration = TRUE) |
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,9 @@ | ||
#' @keywords internal | ||
"_PACKAGE" | ||
|
||
## usethis namespace: start | ||
#' @importFrom Rcpp evalCpp | ||
#' @useDynLib FastUtils, .registration = TRUE | ||
#' @exportPattern "^[[:alpha:]]+" | ||
## usethis namespace: end | ||
NULL |
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,14 @@ | ||
#' Extract Substring from Start to End Difference | ||
#' | ||
#' This function extracts a substring from a given start position to the position determined by subtracting `endDiff` from the string length. | ||
#' | ||
#' @param x A character string from which the substring is extracted. | ||
#' @param start The starting position for the substring extraction. | ||
#' @param endDiff The difference to subtract from the string length to determine the end position. | ||
#' | ||
#' @return A substring of the input character string. | ||
#' @export | ||
#' @keywords character | ||
substrEnd <- function(x, start, endDiff) { | ||
substr(x, start, nchar(x) - endDiff) | ||
} |
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
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
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
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
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,45 @@ | ||
#' Get the Last Elements of a Vector or List | ||
#' | ||
#' This function retrieves the last `n` elements of a vector or list. | ||
#' | ||
#' @param x A vector, list, or other supported data type. | ||
#' @param n An integer specifying the number of elements to retrieve from the end. Default is 1. | ||
#' | ||
#' @return The last `n` elements of the input. | ||
#' @export | ||
#' @keywords indexing | ||
getlast <- function(x, n = 1) { | ||
UseMethod("getlast") | ||
} | ||
|
||
#' @export | ||
getlast.default <- function(x, n = 1) { | ||
index <- length(x) - n + 1 | ||
if (is.list(x)) { | ||
return(x[[index]]) | ||
} | ||
x[index] | ||
} | ||
|
||
#' Get the First Elements of a Vector or List | ||
#' | ||
#' This function retrieves the first `n` elements of a vector or list. | ||
#' | ||
#' @param x A vector, list, or other supported data type. | ||
#' @param n An integer specifying the number of elements to retrieve from the start. Default is 1. | ||
#' | ||
#' @return The first `n` elements of the input. | ||
#' @export | ||
#' @keywords indexing | ||
getfirst <- function(x, n = 1) { | ||
UseMethod("getfirst") | ||
} | ||
|
||
#' @export | ||
getfirst.default <- function(x, n = 1) { | ||
index <- n | ||
if (is.list(x)) { | ||
return(x[[index]]) | ||
} | ||
x[index] | ||
} |
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 |
---|---|---|
@@ -1,29 +1,73 @@ | ||
#' Generate Unique Pairs Up To a Number | ||
#' | ||
#' This function generates all unique pairs of integers up to a given number. | ||
#' | ||
#' @param x An integer specifying the upper limit for pairs. | ||
#' @param oneIndexed A logical indicating whether the pairs should be one-indexed. Default is TRUE. | ||
#' | ||
#' @return A list of unique pairs of integers up to the specified number. | ||
#' @export | ||
#' @keywords iteration | ||
getUniquePairsUpTo <- function(x, oneIndexed = TRUE) { | ||
if (x <= 1) return(list()) | ||
rcppGetUniquePairsUpTo(as.integer(x), oneIndexed = oneIndexed) | ||
} | ||
|
||
#' Zip Multiple Vectors or Lists | ||
#' | ||
#' This function combines multiple vectors or lists element-wise into a list of lists. | ||
#' | ||
#' @param ... Vectors or lists to be combined. | ||
#' | ||
#' @return A list of lists, where each inner list contains the elements from the corresponding positions in the input vectors or lists. | ||
#' @export | ||
getlast <- function(x, n = 1) { | ||
index <- length(x) - n + 1 | ||
if (is.list(x)) return(x[[index]]) | ||
x[index] | ||
} | ||
|
||
#' @export | ||
#' @keywords iteration | ||
zip <- function(...) mapply(list, ..., SIMPLIFY = FALSE) | ||
|
||
#' Enumerate Elements with Indices | ||
#' | ||
#' This function pairs elements of vectors or lists with their indices. | ||
#' | ||
#' @param ... Vectors or lists to be enumerated. | ||
#' @param zero_indexed A logical indicating whether indexing should start from zero. Default is FALSE. | ||
#' | ||
#' @return A list of lists, where each inner list contains an index and the corresponding elements from the input vectors or lists. | ||
#' @export | ||
#' @keywords iteration | ||
enumerate <- function(..., zero_indexed = FALSE) { | ||
zip(seq_along(..1) - zero_indexed, ...) | ||
} | ||
|
||
#' Get Index from Enumerated Element | ||
#' | ||
#' This function extracts the index from an enumerated element. | ||
#' | ||
#' @param elem An enumerated element. | ||
#' | ||
#' @return The index of the enumerated element. | ||
#' @export | ||
#' @keywords iteration | ||
ind <- function(elem) elem[[1]] | ||
|
||
#' Get Value from Enumerated Element by Index | ||
#' | ||
#' This function extracts the value from an enumerated element by the given index. | ||
#' | ||
#' @param elem An enumerated element. | ||
#' @param index The index of the value to extract. | ||
#' | ||
#' @return The value at the specified index in the enumerated element. | ||
#' @export | ||
#' @keywords iteration | ||
val <- function(elem, index) elem[[index + 1]] | ||
|
||
#' Get First Value from Enumerated Element | ||
#' | ||
#' This function extracts the first value from an enumerated element. | ||
#' | ||
#' @param elem An enumerated element. | ||
#' | ||
#' @return The first value in the enumerated element. | ||
#' @export | ||
#' @keywords iteration | ||
val1 <- function(elem) val(elem, 1) |
Oops, something went wrong.