Skip to content

Commit 8df2323

Browse files
author
Kevin Cazelles
committed
test howManyRC() and prettyRange() 🛡️
1 parent b2a7789 commit 8df2323

104 files changed

Lines changed: 3184 additions & 390 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Makefile
55
tests/testthat/*.pdf
66
pkg2date.R
77
record_updates.txt
8-
inst/doc
98
inst/dataFormat
109
inst/tmp
1110

R/howManyRC.R

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,25 @@
33
#' Compute the number of rows and columns to split a graphic window into panels
44
#' as equally as possible.
55
#'
6-
#' @param n a number.
6+
#' @param n a positive integer (or corecible as is).
77
#'
88
#' @export
99
#'
1010
#' @return
1111
#' A vector of two elements: the number of rows followed by the number of columns.
1212

1313
howManyRC <- function(n) {
14+
n <- as.integer(n[1L])
15+
stopifnot(n > 0)
16+
##
1417
sqr <- sqrt(n)
1518
fsq <- floor(sqr)
1619
nbr <- nbc <- fsq
17-
#
18-
if (sqr - fsq != 0)
20+
#
21+
if (sqr - fsq != 0)
1922
nbr <- fsq + 1
20-
if (n - nbr * nbc > 0)
23+
if (n - nbr * nbc > 0)
2124
nbc <- fsq + 1
22-
#
25+
#
2326
c(nbr, nbc)
2427
}

R/prettyRange.R

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#' @export
1111
#'
1212
#' @return
13-
#' A vector of two values that corresponds to the range of values.
13+
#' A vector of two values specifying the pretty the range of values.
1414
#'
1515
#' @details
1616
#' This function intends to generate range with round values.
@@ -24,32 +24,35 @@
2424
#' range(vec)
2525
#' prettyRange(vec)
2626
#' # Example 2:
27-
#' prettyRange(c(3.85,3.88245))
27+
#' prettyRange(c(3.849,3.88245))
2828

2929
prettyRange <- function(x) {
3030
## --- format checking
3131
rgx <- as.numeric(range(x))
32+
## Not that below also test the case where length is 1!
33+
stopifnot(min(rgx) != max(rgx))
3234
## --- Assess the range of values
3335
dif <- rgx[2L] - rgx[1L]
3436
pow <- floor(log(dif, 10))
3537
## --- Get the 'fixed part' (e.g. if the range values is [3.85;3.88] then we set
3638
## 3.8 apart.)
3739
base <- floor(rgx[1L]/10^pow) * 10^pow
3840
rgx <- rgx - base
39-
## ---
41+
## --- Create a sequence of small values to select the min and max
4042
seqp <- 10^(pow + 1) * seq(0, 1.1, 0.05)
4143
minp <- seqp - rgx[1L]
4244
minpa <- abs(minp)
4345
indp <- which(minpa == min(minpa))
44-
if (minp[indp] > 0)
46+
if (minp[indp] > 0)
4547
indp <- indp - 1
4648
rgx[1L] <- seqp[indp]
4749
## ---
4850
maxp <- seqp - rgx[2L]
4951
maxpa <- abs(maxp)
5052
indp <- which(maxpa == min(maxpa))
51-
if (maxp[indp] < 0)
53+
if (maxp[indp] < 0)
5254
indp <- indp + 1
5355
rgx[2L] <- seqp[indp]
54-
return(rgx + base)
56+
##
57+
rgx + base
5558
}

docs/articles/overview.html

Lines changed: 276 additions & 152 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
10.1 KB
119 KB
36.2 KB
39.5 KB
8.15 KB
6.31 KB

0 commit comments

Comments
 (0)