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,
  digits.signif = 6,
  proportional.diff = FALSE,
  dfnames = NULL,
  excelify.col.names = FALSE
)

Arguments

df1

first dataframe or tibble

df2

second dataframe or tibble

digits.signif

When comparing numeric values, what decimal do we want to round to before flagging changes? Also used to limit printing of changes? Numeric, defaults to 4.

proportional.diff

Should flagging of numeric changes be based on absolute differences or the ratio of values, sheet2/sheet? If TRUE, uses digits.signif to identify proportional threshold. proportional.diff = TRUE and digits.signif

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