kevinwolz / hisafer

An R toolbox for the Hi-sAFe biophysical agroforestry model
6 stars 4 forks source link

define_hisafe() throws error for duplicate simulations even when there aren't any #140

Closed kevinwolz closed 4 years ago

kevinwolz commented 4 years ago

The vignette all of sudden was't building because line 130 was throwing an error.

hip <- define_hisafe(path      = "./simulations",
                     profiles  = "all",
                     template  = "agroforestry",
                     exp.name  = "lat-orient",
                     factorial = FALSE,
                     latitude         = c(30, 60),
                     northOrientation = c(0,  90))

The error was thrown as part of the checks performed by check_input_values(). These are the culprit lines:

orig.exp.plan <- hip$exp.plan %>%
    dplyr::mutate_if(is.list, paste_together)
  test.exp.plan <- orig.exp.plan %>%
    dplyr::distinct()

  unique.sim.error     <- ifelse(identical(orig.exp.plan, test.exp.plan),
                                 "", "-- Each simulaton must be distinct.")

Even thought orig.exp.plan and test.exp.plan ARE identical as far as I can tell via any test, identical() is saying they are not! Since identical() is part of the base package, I doubt the issue is there. Instead, I wonder if dplyr::distinct() is erroneously changing something small and behind the scenes about the data frame and tricking identical(). The problem is that I cannot come up with a reproducible example of this outside of the function! So, I can't really report this to dplyr. Instead, I have fixed this by comparing the number of rows of the two data frames instead, which should work just fine for this purpose.