Skip to content

Commit de2dc32

Browse files
author
Kevin Cazelles
committed
test boxplot2 🛡️
1 parent ea50064 commit de2dc32

7 files changed

Lines changed: 53 additions & 24 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: graphicsutils
22
Type: Package
33
Title: Collection of graphics utilities
4-
Version: 1.2-1
4+
Version: 1.3-0
55
Date: 2019-02-16
66
Authors@R: c(person("Kevin", "Cazelles", role = c("aut", "cre"), email = "kcazelle@uoguelph.ca", comment = c(ORCID = "0000-0001-6619-9874")),
77
person("Nicolas", "Casajus", role = c("aut"), comment = c(ORCID = "0000-0002-5537-5294")),
@@ -17,7 +17,6 @@ Imports:
1717
utils,
1818
jpeg (>= 0.1-8),
1919
png (>= 0.1-7),
20-
magrittr (>= 1.5),
2120
Rcpp (>= 0.12.9)
2221
Suggests:
2322
knitr,

R/boxplot2.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ boxplot2 <- function(x, ..., probs = c(.05, 0.25, .5, .75, .95),
5050
val <- apply(as.data.frame(x), 2, quantile, probs = probs)
5151
}
5252
##
53-
if (!add)
54-
plot0(c(.5, ncol(val) +.5), c(range(val)))
55-
##
5653
if (is.null(at)) xco <- 1:ncol(val) else xco <- rep_len(at, ncol(val))
54+
##
55+
if (!add)
56+
plot0(c(.5, ncol(val) + .5), range(val))
57+
5758

5859
for (i in seq_len(ncol(val))) {
5960
single_boxplot(xco[i], val[,i], vc_cex = vc_cex, colors = colors,

R/plotAreaColor.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#'
99
#' @keywords background, color
1010
#'
11-
#' @importFrom magrittr %<>%
1211
#' @export
1312
#'
1413
#' @details The function calls \code{\link{rect}} and draw a colored rectangle (default color is set to light blue) whose dimensions are given by argument `usr` of function \code{\link{par}}.

R/showPalette.R

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#'
1111
#' @keywords color, selection
1212
#'
13-
#' @importFrom magrittr %<>%
14-
#'
1513
#' @return The color palette displayed as an invisible output.
1614
#'
1715
#' @export
@@ -20,10 +18,10 @@
2018
#' showPalette()
2119
#' showPalette(inline=TRUE)
2220
#' showPalette(1)
23-
#' showPalette(sample(1:100, 16), add_number=TRUE, add_codecolor = TRUE)
21+
#' showPalette(sample(1:100, 16), add_number = TRUE, add_codecolor = TRUE)
2422

25-
showPalette <- function(x = grDevices::palette(), inline = FALSE, add_number = FALSE,
26-
add_codecolor = FALSE, cex_num = 1.2) {
23+
showPalette <- function(x = grDevices::palette(), inline = FALSE,
24+
add_number = FALSE, add_codecolor = FALSE, cex_num = 1.2) {
2725

2826
opar <- graphics::par(no.readonly = TRUE)
2927
on.exit(graphics::par(opar))
@@ -36,7 +34,7 @@ showPalette <- function(x = grDevices::palette(), inline = FALSE, add_number = F
3634
}
3735
##
3836
if (class(x) != "matrix")
39-
x %<>% grDevices::col2rgb()
37+
x <- grDevices::col2rgb(x)
4038
ramp <- apply(x, 2, function(x) grDevices::rgb(x[1L], x[2L], x[3L], maxColorValue = 255))
4139
dark <- (apply(x, 2, sum) > 196) + 1
4240
## -- compute the number of column and rows
@@ -53,14 +51,8 @@ showPalette <- function(x = grDevices::palette(), inline = FALSE, add_number = F
5351
for (i in 1:nb_x) {
5452
plot0(fill = ramp[i])
5553
txt <- ""
56-
if (add_number) {
57-
txt %<>% paste0(i)
58-
if (add_codecolor)
59-
txt %<>% paste0(": ", ramp[i])
60-
} else {
61-
if (add_codecolor)
62-
txt %<>% paste0(ramp[i])
63-
}
54+
if (add_number) txt <- paste0(txt, i, ": ")
55+
if (add_codecolor) txt <- paste0(txt, ramp[i])
6456
graphics::text(0, 0, txt, cex = cex_num, col = c("white", "black")[dark[i]])
6557
box2(col = "white")
6658
}

inst/NEWS.Rd

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44
\newcommand{\ghit}{\href{https://github.com/KevCaz/graphicsutils/issues/#1}{##1}}
55

66

7-
\section{Changes in graphicsutils version 1.2-1}{
7+
\section{Changes in graphicsutils version 1.3-0}{
88
\itemize{
99
\item Addition of new functions:
1010
\itemize{
1111
\item new function \code{boxplot2()} that generates boxplots with a different visual that \code{boxplot}.
1212
}
13+
\item Changes in the package's structure:
14+
\itemize{
15+
\item magrittr is no longer imported and change in functions have been made accordingly.
16+
}
1317
\item Change in documentation:
1418
\itemize{
1519
\item The vignette has been reviewed.

tests/testthat/test-boxplot2.R

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
context("test boxplot2")
2+
3+
4+
df_ex <- replicate(4, runif(100))
5+
df_ex2 <- data.frame(nam = rep(LETTERS[1:2], each = 50), val = df_ex[, 1L])
6+
xy <- boxplot2(df_ex)
7+
xy2 <- boxplot2(df_ex, probs = c(.01, 0.25, .5, .75, .99), at = 2:5)
8+
xy3 <- boxplot2(val ~ nam, data = df_ex2)
9+
grDevices::graphics.off()
10+
11+
test_that("expected errors", {
12+
expect_error(boxplot2(df_ex, add = TRUE))
13+
expect_error(boxplot2(df_ex, probs = c(.01)))
14+
expect_error(boxplot2(df_ex, probs = c(.01, 0.25, .5, .75, 2)))
15+
expect_error(boxplot2(df_ex, probs = c(.01, 0.25, .5, .75, -2)))
16+
})
17+
18+
19+
test_that("expected output", {
20+
expect_identical(xy$x, 1:4)
21+
expect_identical(xy2$x, 2:5)
22+
expect_identical(xy3$x, 1:2)
23+
expect_identical(row.names(xy2$y), c("1%", "25%", "50%", "75%", "99%"))
24+
expect_identical(row.names(xy2$y), c("1%", "25%", "50%", "75%", "99%"))
25+
expect_true(
26+
all(
27+
xy2$y[,1] == quantile(df_ex[,1], probs = c(.01, 0.25, .5, .75, .99))
28+
)
29+
)
30+
})
31+
32+
33+
# dfa <- data.frame(name = rep(LETTERS[1:4], 25), val = runif(100))
34+
# boxplot2(val ~ name, data = dfa, add = TRUE, vc_cex = c(4, 40, 2))

tests/testthat/test-pointsInPolygon.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ res <- pointsInPolygon(pts, tria)
66

77

88
test_that("does it work properly", {
9-
expect_true(all(res == c(T, F, F)))
9+
expect_true(all(res == c(TRUE, FALSE, FALSE)))
1010
})
1111

1212
test_that("expected warnings", {
13-
expect_warning(pointsInPolygon(cbind(tria,0), pts), "ncol(points)>2 - only the first two columns are used.", fixed = T)
14-
expect_warning(pointsInPolygon(tria, cbind(pts, 0)), "ncol(polygon)>2 - only the first two columns are used.", fixed = T)
13+
expect_warning(pointsInPolygon(cbind(tria,0), pts), "ncol(points)>2 - only the first two columns are used.", fixed = TRUE)
14+
expect_warning(pointsInPolygon(tria, cbind(pts, 0)), "ncol(polygon)>2 - only the first two columns are used.", fixed = TRUE)
1515
})

0 commit comments

Comments
 (0)