Skip to content

Commit 4fde89a

Browse files
author
Kevin Cazelles
committed
additionnal unit testings for plot0 ⚙️
1 parent 2eb3fe9 commit 4fde89a

5 files changed

Lines changed: 35 additions & 18 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ Depends:
1111
Imports:
1212
grDevices,
1313
graphics,
14+
methods,
1415
stats,
1516
utils,
1617
jpeg(>= 0.1-8),
1718
png(>= 0.1-7),
1819
magrittr(>= 1.5),
19-
downloader(>= 0.4),
2020
RCurl(>= 1.95-4.7),
2121
Suggests:
2222
knitr,

R/plot0.R

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,35 @@
1717
#' @seealso \code{\link[shape]{emptyplot}}
1818
#'
1919
#' @examples
20-
#' # Example 1:
20+
#' # Example 1
2121
#' plot0()
2222
#'
23-
#' # Example 2:
23+
#' # Example 2
2424
#' plot0(c(-10,10), asp=1)
2525
#'
26-
#' # Example 2:
27-
#' plot0(c(-10,10), asp=1, fill=8, text='cool', srt=90, cex=2)
26+
#' # Example 3
27+
#' plot0(c(-10,10), text='cool', cex = 2)
28+
#'
29+
#' # Example 3
2830
#' plot0(c(-10,10), asp=1, fill=8, text='cool', srt=45, cex=4, col=2)
2931

3032
plot0 <- function(x = c(-1, 1), y = NULL, fill = NULL, text = NULL, ...) {
33+
##
3134
args <- list(...)
32-
coor <- list(x = x, y = y)
35+
args_txt <- args[names(args) %in% methods::formalArgs(graphics::text.default)]
3336
deft <- list(ann = FALSE, axes = FALSE, type = "n")
34-
##--- default behavior for matrix and vectors
37+
# default behavior for matrix and vectors
3538
if (NCOL(as.matrix(x)) > 1 & is.null(y)) {
3639
if (is.null(y)) {
3740
y <- x[, 2L]
3841
}
3942
x <- x[, 1L]
4043
} else {
41-
if (is.null(y)) {
42-
y <- x
43-
}
44+
if (is.null(y))
45+
y <- x else stopifnot(length(x) == length(y))
4446
}
45-
47+
#
48+
coor <- list(x = x, y = y)
4649

4750
##
4851
if (length(args) > 0) {
@@ -51,12 +54,13 @@ plot0 <- function(x = c(-1, 1), y = NULL, fill = NULL, text = NULL, ...) {
5154
deft <- deft[-id]
5255
do.call(graphics::plot.default, args = as.list(c(coor, args, deft)))
5356
} else graphics::plot.default(x = x, y = y, ann = FALSE, axes = FALSE, type = "n")
54-
##
57+
5558
if (!is.null(fill))
5659
plotAreaColor(color = fill)
5760
##
5861
if (!is.null(text))
59-
text(mean(x), mean(y), labels = as.character(text), ...)
62+
do.call(graphics::text.default, args = as.list(c(x = mean(x), y = mean(y),
63+
labels = as.character(text), args_txt)))
6064
##
6165
invisible(NULL)
6266
}

man/plot0.Rd

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

tests/testthat/test-plot0.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,19 @@ plot0(x=c(0,1), y=c(0,2), xlim=c(0,10), fill=2)
1010
pus2 <- par()$usr
1111
dev.off()
1212

13+
##
14+
plot0(x=cbind(c(0,1), c(0,2)), text="test")
15+
pus3 <- par()$usr
16+
dev.off()
17+
18+
19+
1320
test_that("test par()$usr dimensions", {
1421
expect_true(all(pus1 == c(-1.08, 1.08, -1.08, 1.08)))
1522
expect_true(all(pus2 == c(-0.40, 10.40, -0.08, 2.08)))
23+
expect_true(all(pus3 == c(-0.04, 1.04, -0.08, 2.08)))
24+
})
25+
26+
test_that("expected errors", {
27+
expect_error(plot0(1, c(1,1)), "length(x) == length(y) is not TRUE", fixed = T)
1628
})

vignettes/graphicsutilsDemo.Rmd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ output: rmarkdown::html_vignette
44
vignette: >
55
%\VignetteEngine{knitr::rmarkdown}
66
%\VignetteIndexEntry{Vignette Title}
7-
\usepackage[utf8]{inputenc}
87
abstract: "The package graphicsutils is a set of miscellaneous functions to be used with the graphics library."
98
author: Kevin Cazelles
109
---

0 commit comments

Comments
 (0)