Skip to content

Commit

Permalink
styler
Browse files Browse the repository at this point in the history
  • Loading branch information
dunkenwg committed Jan 9, 2025
1 parent d79beb6 commit 588aace
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 27 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ Suggests:
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.2
Roxygen: list(markdown = TRUE)
9 changes: 6 additions & 3 deletions R/colors.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
#' @export
set_colors <- function(values = get_colors()) {
chk_string(values)
if (length(values) < 6)
if (length(values) < 6) {
stop("there must be at least 6 color values")
}

options(poiscon.colors = values)
invisible(values)
Expand All @@ -24,6 +25,8 @@ set_colors <- function(values = get_colors()) {
#' @return color palette as character vector
#' @export
get_colors <- function() {
getOption("poiscon.colors", c("black", "red", "blue", "green4", "orange3",
"slategray", "purple"))
getOption("poiscon.colors", c(
"black", "red", "blue", "green4", "orange3",
"slategray", "purple"
))
}
16 changes: 10 additions & 6 deletions R/nfold.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ prop2nfold <- function(x) {
x <- as.numeric(x)
chk_vector(x)
check_values(x, c(0, NA_real_))
if(!length(x)) return(x)
ifelse(x >= 0, x, -(x+1)^-1+1)
if (!length(x)) {
return(x)
}
ifelse(x >= 0, x, -(x + 1)^-1 + 1)
}

#' @describeIn prop2nfold N-fold Change to Proportional Change
Expand All @@ -22,8 +24,10 @@ nfold2prop <- function(x) {
x <- as.numeric(x)
chk_vector(x)
check_values(x, c(0, NA_real_))
if(!length(x)) return(x)
ifelse(x >= 0, x, -(x-1)^-1-1)
if (!length(x)) {
return(x)
}
ifelse(x >= 0, x, -(x - 1)^-1 - 1)
}

#' N-fold Breaks
Expand All @@ -34,7 +38,7 @@ nfold2prop <- function(x) {
#' @export
#'
#' @examples
#' nfold_breaks()(c(-3/4,-2/3,-1/2,0,1,2,3))
#' nfold_breaks()(c(-3 / 4, -2 / 3, -1 / 2, 0, 1, 2, 3))
nfold_breaks <- function(n = 5) {
force(n)
function(x) {
Expand All @@ -54,7 +58,7 @@ nfold_trans <- function() {

#' N-fold Position Scales
#'
#' scale_x_nfold() and scale_y_nfold() are variants of \code{\link{scale_x_continuous}()}
#' scale_x_nfold() and scale_y_nfold() are variants of [scale_x_continuous()]
#' that set the trans argument to transform proportional change to n-fold change.
#' @inheritParams ggplot2::scale_x_continuous
#'
Expand Down
2 changes: 1 addition & 1 deletion R/theme-Poisson.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' A gg theme for Poisson style plots.
#'
#' To use, ensure ggplot2 is installed and then call
#' \code{theme_set(theme_Poisson())}.
#' `theme_set(theme_Poisson())`.
#'
#' @param base_size an integer scalar indicating the base font size.
#' @param base_family a character scalar indicating the base font family.
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ library(poisplot)
library(ggplot2)
library(scales)
data <- data.frame(y = c(-3/4,-2/3,-1/2,0,1,2,3))
data <- data.frame(y = c(-3 / 4, -2 / 3, -1 / 2, 0, 1, 2, 3))
data$x <- 1:nrow(data)
gp <- ggplot(data, aes(x = x, y = y)) +
Expand Down
2 changes: 1 addition & 1 deletion man/scale_x_nfold.Rd

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

10 changes: 7 additions & 3 deletions tests/testthat/test-colors.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
test_that("get_colors", {
expect_identical(get_colors(),
c("black", "red", "blue", "green4", "orange3",
"slategray", "purple"))
expect_identical(
get_colors(),
c(
"black", "red", "blue", "green4", "orange3",
"slategray", "purple"
)
)
})
28 changes: 17 additions & 11 deletions tests/testthat/test-nfold.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
test_that("nfold2prop" ,{
expect_equal(prop2nfold(c(-1,-2/3,-1/2,0,1/2,1,2,Inf)),
c(-Inf, -2.0, -1.0, 0.0, 0.5, 1.0, 2.0, Inf))
expect_equal(nfold2prop(prop2nfold(c(-1,-2/3,-1/2,0,1/2,1,2,Inf))),
c(-1,-2/3,-1/2,0,1/2,1,2,Inf))
test_that("nfold2prop", {
expect_equal(
prop2nfold(c(-1, -2 / 3, -1 / 2, 0, 1 / 2, 1, 2, Inf)),
c(-Inf, -2.0, -1.0, 0.0, 0.5, 1.0, 2.0, Inf)
)
expect_equal(
nfold2prop(prop2nfold(c(-1, -2 / 3, -1 / 2, 0, 1 / 2, 1, 2, Inf))),
c(-1, -2 / 3, -1 / 2, 0, 1 / 2, 1, 2, Inf)
)
})

test_that("nfold_breaks" ,{
expect_equal(nfold_breaks()(c(-3/4,-2/3,-1/2,0,1,2,3)),
c(-0.75, -0.6666667, -0.5, 0, 1, 2, 3), tolerance = 1e-07)
test_that("nfold_breaks", {
expect_equal(nfold_breaks()(c(-3 / 4, -2 / 3, -1 / 2, 0, 1, 2, 3)),
c(-0.75, -0.6666667, -0.5, 0, 1, 2, 3),
tolerance = 1e-07
)
})

test_that("nfold_trans" ,{
test_that("nfold_trans", {
expect_is(nfold_trans(), "trans")
})

test_that("scale_y/x_nfold", {
expect_equal(scale_y_nfold(), scale_y_continuous(trans = nfold_trans()))
expect_equal(scale_x_nfold(), scale_x_continuous(trans = nfold_trans()))
expect_equal(scale_y_nfold(), scale_y_continuous(trans = nfold_trans()))
expect_equal(scale_x_nfold(), scale_x_continuous(trans = nfold_trans()))
})
2 changes: 1 addition & 1 deletion tests/testthat/test-theme-Poisson.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
test_that("theme_Poisson" ,{
test_that("theme_Poisson", {
expect_is(theme_Poisson(), c("theme", "gg"))
})

0 comments on commit 588aace

Please sign in to comment.