Skip to contents

Workhorse function for excel_diff_table(). Can be used to diff any pair of dataframes or tibbles. Diff is applied cell by cell, so results will only be meaningful if the shape of the two objects is the same.

Usage

diff_to_table(
  df1,
  df2,
  proportional_threshold = 0.001,
  absolute_threshold = NULL,
  digits_show = 6,
  dfnames = NULL,
  excelify_col_names = FALSE
)

Arguments

df1

first dataframe or tibble

df2

second dataframe or tibble

proportional_threshold

Sets a threshold of proportional change below which differences should be ignored. For example, a value of 0.1 means any changes less than 10% will not be flagged as having changed. proportional_threshold will override this value and behavior if it is provided. Numeric, defaults to 0.001 (0.1% change).

absolute_threshold

Optional. Sets a threshold of absolute change below which differences should be ignored. For example, a value of 0.1 means any changes less than 0.1 will not be flagged as having changed. If provided, will override proportional_threshold. Numeric, defaults to NULL.

digits_show

When there is a change in number values, how many digits should be shown in ## ---> ##? Numeric, defaults to 6. Recommend not making this so small that flagged changes don't get printed (e.g., if this is 2 and proportional_threshold is 0.001, 0.1% changes will get flagged, but only the first two digits will get shown).

dfnames

Character vector with names of the two dataframes to use for table title. Optional.

excelify_col_names

Should columns be identified by excel letter convention? Defaults to FALSE. Set to TRUE when comparing dataframes extracted from excel sheets.

Value

flextable object

Examples

df1 <- mtcars
df2 <- mtcars
df2[2, 2] <- -8
df2[5, c(3, 4)] <- c(11, 15)
diff_to_table(df1, df2)
Diff table

ROW

mpg

cyl

disp

hp

drat

wt

qsec

vs

am

gear

carb

2

21.0

6

160

110

3.90

2.875

17.02

0

1

4

4

2

21.0

-8

160

110

3.90

2.875

17.02

0

1

4

4

5

18.7

8

360

175

3.15

3.440

17.02

0

0

3

2

5

18.7

8

11

15

3.15

3.440

17.02

0

0

3

2