tbl_df
using all.equal
, column and
row order is ignored by default, and types are not coerced. The dplyr
package provides a much more efficient implementation for this functionality.all_equal(target, current, ignore_col_order = TRUE, ignore_row_order = TRUE,
convert = FALSE, ...)## S3 method for class 'tbl_df':
all.equal(target, current, ignore_col_order = TRUE,
ignore_row_order = TRUE, convert = FALSE, ...)
all.equal
.TRUE
if equal, otherwise a character vector describing
the reasons why they're not equal. Use isTRUE
if using the
result in an if
expression.scramble <- function(x) x[sample(nrow(x)), sample(ncol(x))]
mtcars_df <- as_data_frame(mtcars)
# By default, ordering of rows and columns ignored
all.equal(mtcars_df, scramble(mtcars_df))
# But those can be overriden if desired
all.equal(mtcars_df, scramble(mtcars_df), ignore_col_order = FALSE)
all.equal(mtcars_df, scramble(mtcars_df), ignore_row_order = FALSE)
# By default all.equal is sensitive to variable differences
df1 <- data_frame(x = "a")
df2 <- data_frame(x = factor("a"))
all.equal(df1, df2)
# But you can request to convert similar types
all.equal(df1, df2, convert = TRUE)
Run the code above in your browser using DataLab