
Convert Data to Match Original Class
convert_data.RdConverts a dataset to have the same class as another reference dataset. This is useful for ensuring consistent output formats when performing operations that temporarily convert data structures (e.g., between `data.table`, `data.frame`, or `tibble`).
Details
The function checks the class of data_original in the following order:
If it is a tibble (`tbl_df`),
datais converted usingtibble::as_tibble().If it is a base data frame but not a data.table,
datais converted usingas.data.frame().Otherwise,
datais returned unchanged (e.g., for data.table input).
Examples
if (FALSE) { # \dontrun{
df <- data.frame(x = 1:3)
dt <- data.table::as.data.table(df)
# Convert dt back to data.frame to match df
convert_data(dt, df)
# Convert to tibble if original was tibble
convert_data(dt, tibble::as_tibble(df))
} # }