CompareFiles: Compare HYPE model files to identify any differences.

View source: R/function_CompareFiles.R

CompareFilesR Documentation

Compare HYPE model files to identify any differences.

Description

Compare HYPE model files to identify any differences, typically used to check that no undesired changes were made when writing a new file.

Usage

CompareFiles(
  x,
  y,
  type = c("AquiferData", "BasinOutput", "BranchData", "CropData", "DamData", "ForcKey",
    "FloodData", "GeoClass", "GeoData", "Info", "LakeData", "MapOutput", "MgmtData",
    "Optpar", "Par", "PointSourceData", "Obs", "Simass", "Subass", "TimeOutput", "Xobs"),
  by = NULL,
  compare.order = TRUE,
  threshold = 1e-10,
  ...
)

Arguments

x

Path to a HYPE model file to read, or an existing list/data frame object for a HYPE model file. File contents are compared to those of y.

y

Path to a HYPE model file to read, or an existing list/data frame object for a HYPE model file. File contents are compared to those of x.

type

Character string identifying the type of HYPE model file. Used to determine appropriate read function. One of AquiferData, BasinOutput, BranchData, CropData, DamData, ForcKey, FloodData, GeoClass, GeoData, Info, LakeData, MapOutput, MgmtData, Optpar, Par, PointSourceData, Obs, Simass, Subass, TimeOutput, or Xobs.

by

Character vector, names of columns in x and y to use to join data. See dplyr::full_join.

compare.order

Logical, whether or not the order of the rows should be compared. If TRUE, then x and y will also be joined by row number. See dplyr::full_join.

threshold

Numeric, threshold difference for comparison of numeric values. Set to 0 to only accept identical values.

...

Other arguments passed on to functions to read the files to compare (e.g. ReadGeoData, ReadPar, etc.).

Details

CompareFiles compares two HYPE model files and identifies any differences in values. The function reads two model files, compares the values in columns with corresponding names, and returns a data frame consisting of rows/columns with any differences. Values that are the same in both files are set to NA. If numeric values in two columns aren't exactly the same, then the difference between the values will be taken and compare to theshold. If the difference is <= theshold, then the values will be considered the equal and set to NA. The function is primarily intended as a check to ensure that no unintended changes were made when writing model files using the various HYPEtools write functions. However, it can also be used to e.g. compare files between different model versions.

Value

Returns invisibly a data frame containing rows and columns in which differences exist between x and y. Values that are the same in both files are set to NA. If the returned data frame has 0 row, then there were no differences between the files.

Examples

# Import demo model GeoData file, edit a SUBID
te1 <- ReadGeoData(filename = system.file("demo_model", "GeoData.txt", package = "HYPEtools"))
te1$SUBID[1] <- 1
# Compare with original file
te2 <- CompareFiles(system.file("demo_model", "GeoData.txt", package = "HYPEtools"), te1, 
                    type = "GeoData")
te2


HYPEtools documentation built on Sept. 11, 2024, 8:34 p.m.