Skip to content

Commit 4ff8243

Browse files
committed
improve comments
1 parent cfd4962 commit 4ff8243

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

R/annotation.r

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,13 @@ annotate <- function(geom, x = NULL, y = NULL, xmin = NULL, xmax = NULL,
4646

4747
# Check that all aesthetic have compatible lengths
4848
lengths <- vapply(aesthetics, length, integer(1))
49-
n <- unique(setdiff(lengths, 1L))
50-
if (length(n) == 0L) n <- 1L # if all lengths are equal to 1L then above line fails, this fixes that
49+
50+
# To determine the final number of rows `n` in the data frame,
51+
# we need to find the unique lengths not equal to 1L (and there
52+
# should be at most one such length). However, if all lengths
53+
# are equal to 1L, then the final number of rows is also 1L.
54+
n <- unique(setdiff(lengths, 1L)) # unique lengths except 1L
55+
if (length(n) == 0L) n <- 1L # all lengths are equal to 1L
5156

5257
if (length(n) > 1L) {
5358
bad <- lengths != 1L

tests/testthat/test-performance.R

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
context("Performance related alternatives")
22

3-
# ********************
4-
# modify_list()
3+
# modify_list() -----------------------------------------------------------
54

65
testlist <- list(
76
a = 5.5,
@@ -37,8 +36,7 @@ test_that("modify_list erases null elements", {
3736
})
3837

3938

40-
# ********************
41-
# new_data_frame()
39+
# new_data_frame() --------------------------------------------------------
4240

4341
test_that("new_data_frame handles zero-length inputs", {
4442
# zero-length input creates zero-length data frame

0 commit comments

Comments
 (0)