@@ -64,10 +64,14 @@ print_out <- function(x, ...) {
6464# Common helpers ---------------------------------------------------------------
6565
6666same_length <- function (x , y ) length(x ) == length(y )
67- diff_length <- function (x , y ) difference(fmt = " Lengths differ: %i is not %i" , length(x ), length(y ))
67+ diff_length <- function (x , y ) {
68+ difference(fmt = " Lengths differ: %i is not %i" , length(x ), length(y ))
69+ }
6870
6971same_type <- function (x , y ) identical(typeof(x ), typeof(y ))
70- diff_type <- function (x , y ) difference(fmt = " Types not compatible: %s is not %s" , typeof(x ), typeof(y ))
72+ diff_type <- function (x , y ) {
73+ difference(fmt = " Types not compatible: %s is not %s" , typeof(x ), typeof(y ))
74+ }
7175
7276same_class <- function (x , y ) {
7377 if (! is.object(x ) && ! is.object(y )) {
@@ -76,7 +80,11 @@ same_class <- function(x, y) {
7680 identical(class(x ), class(y ))
7781}
7882diff_class <- function (x , y ) {
79- difference(fmt = " Classes differ: %s is not %s" , format_class(class(x )), format_class(class(y )))
83+ difference(
84+ fmt = " Classes differ: %s is not %s" ,
85+ format_class(class(x )),
86+ format_class(class(y ))
87+ )
8088}
8189
8290same_attr <- function (x , y ) {
@@ -91,10 +99,9 @@ vector_equal <- function(x, y) {
9199 (is.na(x ) & is.na(y )) | (! is.na(x ) & ! is.na(y ) & x == y )
92100}
93101
94- vector_equal_tol <- function (x , y , tolerance = .Machine $ double.eps ^ 0.5 ) {
102+ vector_equal_tol <- function (x , y , tolerance = .Machine $ double.eps ^ 0.5 ) {
95103 (is.na(x ) & is.na(y )) |
96104 (! is.na(x ) & ! is.na(y )) & (x == y | abs(x - y ) < tolerance )
97-
98105}
99106
100107
@@ -125,9 +132,15 @@ vector_equal_tol <- function(x, y, tolerance = .Machine$double.eps ^ 0.5) {
125132# ' compare(x, y)
126133# ' compare(c(x, x), c(y, y))
127134# '
128- compare.character <- function (x , y , check.attributes = TRUE , ... ,
129- max_diffs = 5 , max_lines = 5 ,
130- width = cli :: console_width()) {
135+ compare.character <- function (
136+ x ,
137+ y ,
138+ check.attributes = TRUE ,
139+ ... ,
140+ max_diffs = 5 ,
141+ max_lines = 5 ,
142+ width = cli :: console_width()
143+ ) {
131144 if (identical(x , y )) {
132145 return (no_difference())
133146 }
@@ -174,10 +187,13 @@ mismatch_character <- function(x, y, diff = !vector_equal(x, y)) {
174187}
175188
176189# ' @export
177- format.mismatch_character <- function (x , ... ,
178- max_diffs = 5 ,
179- max_lines = 5 ,
180- width = cli :: console_width()) {
190+ format.mismatch_character <- function (
191+ x ,
192+ ... ,
193+ max_diffs = 5 ,
194+ max_lines = 5 ,
195+ width = cli :: console_width()
196+ ) {
181197 width <- width - 6 # allocate space for labels
182198 n_show <- seq_len(min(x $ n_diff , max_diffs ))
183199
@@ -186,11 +202,16 @@ format.mismatch_character <- function(x, ...,
186202 show_y <- str_trunc(encode(x $ y [n_show ]), width * max_lines )
187203 show_i <- x $ i [n_show ]
188204
189- sidebyside <- Map(function (x , y , pos ) {
190- x <- paste0(" x[" , pos , " ]: " , str_chunk(x , width ))
191- y <- paste0(" y[" , pos , " ]: " , str_chunk(y , width ))
192- paste(c(x , y ), collapse = " \n " )
193- }, show_x , show_y , show_i )
205+ sidebyside <- Map(
206+ function (x , y , pos ) {
207+ x <- paste0(" x[" , pos , " ]: " , str_chunk(x , width ))
208+ y <- paste0(" y[" , pos , " ]: " , str_chunk(y , width ))
209+ paste(c(x , y ), collapse = " \n " )
210+ },
211+ show_x ,
212+ show_y ,
213+ show_i
214+ )
194215
195216 summary <- paste0(x $ n_diff , " /" , x $ n , " mismatches" )
196217 paste0(summary , " \n " , paste0(sidebyside , collapse = " \n\n " ))
@@ -238,13 +259,20 @@ str_chunk <- function(x, length) {
238259# ' # Compare ignores minor numeric differences in the same way
239260# ' # as all.equal.
240261# ' compare(x, x + 1e-9)
241- compare.numeric <- function (x , y ,
242- tolerance = testthat_tolerance(),
243- check.attributes = TRUE ,
244- ... , max_diffs = 9 ) {
262+ compare.numeric <- function (
263+ x ,
264+ y ,
265+ tolerance = testthat_tolerance(),
266+ check.attributes = TRUE ,
267+ ... ,
268+ max_diffs = 9
269+ ) {
245270 all_equal <- all.equal(
246- x , y , tolerance = tolerance ,
247- check.attributes = check.attributes , ...
271+ x ,
272+ y ,
273+ tolerance = tolerance ,
274+ check.attributes = check.attributes ,
275+ ...
248276 )
249277 if (isTRUE(all_equal )) {
250278 return (no_difference())
@@ -284,7 +312,7 @@ testthat_tolerance <- function() {
284312 skip(" Long doubles not available and `tolerance` not supplied" )
285313 }
286314
287- .Machine $ double.eps ^ 0.5
315+ .Machine $ double.eps ^ 0.5
288316}
289317
290318mismatch_numeric <- function (x , y , diff = ! vector_equal(x , y )) {
@@ -312,7 +340,8 @@ format.mismatch_numeric <- function(x, ..., max_diffs = 9, digits = 3) {
312340 n_show <- seq_len(min(x $ n_diff , max_diffs ))
313341
314342 diffs <- paste0(
315- format(paste0(" [" , x $ i [n_show ], " ]" )), " " ,
343+ format(paste0(" [" , x $ i [n_show ], " ]" )),
344+ " " ,
316345 format(x $ x [n_show ], digits = digits ),
317346 " - " ,
318347 format(x $ y [n_show ], digits = digits ),
@@ -362,10 +391,11 @@ compare.POSIXt <- function(x, y, tolerance = 0.001, ..., max_diffs = 9) {
362391}
363392
364393standardise_tzone <- function (x ) {
365- if (is.null(attr(x , " tzone" )) || identical(attr(x , " tzone" ), Sys.timezone())) {
394+ if (
395+ is.null(attr(x , " tzone" )) || identical(attr(x , " tzone" ), Sys.timezone())
396+ ) {
366397 attr(x , " tzone" ) <- " "
367398 }
368399
369400 x
370401}
371-
0 commit comments