Skip to content

Commit

Permalink
small fixes across the board
Browse files Browse the repository at this point in the history
  • Loading branch information
Qile0317 committed May 26, 2024
1 parent a4521bb commit 2967dae
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 26 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: FastUtils
Type: Package
Title: Fast, readable utility functions.
Title: Fast, readable utility functions
Version: 0.1.0
Date: 2024-05-23
Authors@R: c(person("Qile", "Yang", email = "[email protected]", role = c("cre","aut","cph")))
Expand All @@ -17,6 +17,7 @@ Imports:
lifecycle,
magrittr,
Rcpp (>= 1.0.12),
rlang,
testthat,
usethis,
yaml
Expand Down
4 changes: 3 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export(sykr)
export(syncYMLKeywordRefs)
export(tableToNumeric)
export(test_quietly_that)
export(trySplitVar)
export(trySplitVarStr)
export(val)
export(val1)
export(warningp)
Expand All @@ -59,4 +59,6 @@ exportPattern("^[[:alpha:]]+")
importFrom(Rcpp,evalCpp)
importFrom(lifecycle,deprecated)
importFrom(magrittr,"%>%")
importFrom(methods,is)
importFrom(rlang,":=")
useDynLib(FastUtils, .registration = TRUE)
2 changes: 2 additions & 0 deletions R/FastUtils-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#' @exportPattern "^[[:alpha:]]+"
#' @importFrom lifecycle deprecated
#' @importFrom magrittr %>%
#' @importFrom rlang :=
#' @importFrom methods is
#' @importFrom Rcpp evalCpp
#' @useDynLib FastUtils, .registration = TRUE
## usethis namespace: end
Expand Down
5 changes: 4 additions & 1 deletion R/color.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
#' @examples
#' getAvgHex("#00000", "#FF00FF")
#' getAvgHex(c("#008040", "#00000", "#FF00FF"))
#' getAvgHex(list("#008040", "#00000"), "#FF00FF", c("#FF00FF"))
#'
#' # very nonstandard but possible way to input hexes. Essentially,
#' any combination of vectors will work.
#' getAvgHex(list("#008040", "#000000"), "#FF00FF", c("#FF00FF"))
#'
getAvgHex <- function(...) {

hex_vector <- unlist(list(...))
Expand Down
4 changes: 3 additions & 1 deletion R/interactivity.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@
#' print(a)
#' })
#'
quietly <- function(e) suppressMessages(invisible(capture.output(e)))
quietly <- function(e) {
suppressMessages(invisible(utils::capture.output(e)))
}
2 changes: 1 addition & 1 deletion R/packageDevelopment.R
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ addYMLKeywordRefs <- function(
getExistingFilePath <- function(filePath, dir = ".") {
if (!dir.exists(dir)) stopp("Specified directory does not exist.")
fullFilePath <- file.path(dir, filePath)
if (!file.exists(fullYmlPath)) stopp("The specified file was not found.")
if (!file.exists(fullFilePath)) stopp("The specified file was not found.")
fullFilePath
}

Expand Down
27 changes: 17 additions & 10 deletions R/spelling.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,30 @@
#' any of these conventions, it returns the original string.
#'
#' @param x A character string or vector to be analyzed and split.
#' @param conseq A logical indicating whether the `conseq` argument in [splitCamel()]/
#' [splitPascal()] should be `TRUE` or `FALSE`.
#' @param strictSnake A logical indicating the `strict` argument in [isSnakeCase()].
#'
#' @return A list of character vectors, each containing the parts of the string
#' split according to its naming convention or the original string if no
#' convention matches.
#' @export
#' @keywords spelling
#' @seealso \code{\link{splitCamel}}, \code{\link{splitPascal}}, \code{\link{splitSnake}},
#' \code{\link{isCamelCase}}, \code{\link{isPascalCase}}, \code{\link{isSnakeCase}}
#'
#' @examples
#' trySplitVar("camelCaseExample")
#' trySplitVar("PascalCaseExample")
#' trySplitVar("snake_case_example")
#' trySplitVar("no_special_case")
#' @export
#' @keywords spelling
trySplitVar <- function(x) {
#' trySplitVarStr("camelCaseExample")
#' trySplitVarStr("PascalCaseExample")
#' trySplitVarStr("snake_case_example")
#' trySplitVarStr("some|random|case")
#'
trySplitVarStr <- function(x, conseq = TRUE, strictSnake = FALSE) {
lapply(x, function(y) {
if (isCamelCase(y) || isPascalCase(y)) {
return(unlist(splitCamel(y)))
return(unlist(splitCamel(y, conseq = isTRUE(conseq))))
}
if (isSnakeCase(y)) {
if (isSnakeCase(y, strict = isTRUE(strictSnake))) {
return(unlist(splitSnake(y)))
}
y
Expand Down Expand Up @@ -60,7 +66,8 @@ splitCamel <- function(x, conseq = TRUE) {
perl = TRUE
))
}
strsplit(gsub("([A-Z]{1})", " \\1", x), " ")
strsplit(gsub("([A-Z]{1})", " \\1", x), " ") %>%
lapply(function(y) if (y[1] == "") y[-1] else y)
}

#' @rdname splitCamel
Expand Down
2 changes: 1 addition & 1 deletion inst/CITATION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
bibentry(
bibtype = "manual",
title = FastUtils,
author = Qile Yang,
author = "Qile Yang",
year = 2024
)
2 changes: 1 addition & 1 deletion man/FastUtils-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/getAvgHex.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 13 additions & 7 deletions man/trySplitVar.Rd → man/trySplitVarStr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion tests/testthat/test-ggplot.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
test_that("Get the xmin, xmax, ymin, ymax of a ggplot Object", {
result <- getPlotDims(ggplot(data.frame(x = c(1, 2, 3), y = c(1, 2, 3)), aes(x, y)) + geom_point())
result <- getPlotDims(
ggplot2::ggplot(data.frame(x = c(1, 2, 3), y = c(1, 2, 3))) +
ggplot2::geom_point(ggplot2::aes(x, y))
)
expect_equal(result$xr, c(1, 3))
expect_equal(result$yr, c(1, 3))
})

0 comments on commit 2967dae

Please sign in to comment.