densitymodelling / dsmextra

Extrapolation assessments in density surface models
GNU Lesser General Public License v3.0
4 stars 3 forks source link

compare_covariates, Error: Column names `extrapolation.univariate.n`...must not be duplicated #9

Closed FGrossmann closed 4 years ago

FGrossmann commented 4 years ago

Running compare_covariates stops with the following error for both the spermwhales dataset or own data:

Error: Column names extrapolation.univariate.n, extrapolation.univariate.n, extrapolation.univariate.n, extrapolation.univariate.n, extrapolation.univariate.n, and 10 more must not be duplicated. Run rlang::last_error() to see where the error occurred.

Output of rlang::last_error() attached below. I could not trace the issue based on the provided traceback.

Running the code elemnets the error is thrown in line 446 & 449

`if(extrapolation.type=="both"){

  var.ind.univariate <- purrr::map_df(.x = var.ind, .f = ~vars.univariate[.]) %>%
    tidyr::gather(data = .)

  var.ind.combinatorial <- purrr::map_df(.x = var.ind, .f = ~vars.combinatorial[.]) %>%
    tidyr::gather(data = .)`

I believe .f is expecting a numeric class without attr., and indeed the following works: var.ind.univariate <- purrr::map_df(.x = var.ind, .f = ~as.numeric(vars.univariate[.])) %>% tidyr::gather(data = .)

Tracing the origin of the vars.univariate variable, it is based on the output of retrieve numbers of cells from the extrapolation, lines 213-219, with the following code:

vars <- exsum %>% purrr::map(.x = ., .f = ~.x[names(.x)%in%paste0(extype, ".n")]) %>% unlist(.)

Setting the function unlist(.), with unlist(. , use.names = FALSE) solves the issue for me.

sessionInfo() R version 3.6.1 (2019-07-05) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 18362)

Matrix products: default

locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] ggplot2_3.3.1 dsmextra_1.1.0 dismo_1.1-4 raster_3.1-5
[5] sp_1.4-2 sf_0.9-3 dplyr_1.0.0 ProjectTemplate_0.9.2

loaded via a namespace (and not attached): [1] xfun_0.14 tidyselect_1.1.0 remotes_2.1.1 purrr_0.3.4 lattice_0.20-38
[6] colorspace_1.4-1 vctrs_0.3.1 generics_0.0.2 htmltools_0.4.0 utf8_1.1.4
[11] rlang_0.4.6 pkgbuild_1.0.8 startup_0.14.1 e1071_1.7-3 pillar_1.4.4
[16] glue_1.4.1 withr_2.2.0 DBI_1.1.0 lifecycle_0.2.0 plyr_1.8.6
[21] munsell_0.5.0 gtable_0.3.0 htmlwidgets_1.5.1 codetools_0.2-16 labeling_0.3
[26] knitr_1.28 callr_3.4.3 ps_1.3.3 crosstalk_1.1.0.1 curl_4.3
[31] class_7.3-15 fansi_0.4.1 highr_0.8 Rcpp_1.0.4.6 KernSmooth_2.23-15 [36] backports_1.1.7 scales_1.1.1 classInt_0.4-3 leaflet_2.0.3 farver_2.0.3
[41] packrat_0.4.8-1 digest_0.6.25 processx_3.4.2 cowplot_1.0.0 grid_3.6.1
[46] rprojroot_1.3-2 here_0.1 rgdal_1.5-8 cli_2.0.2 tools_3.6.1
[51] magrittr_1.5 tibble_3.0.1 crayon_1.3.4 tidyr_1.1.0 pkgconfig_2.0.3
[56] ellipsis_0.3.1 prettyunits_1.1.1 assertthat_0.2.1 rstudioapi_0.11 R6_2.4.1
[61] units_0.6-6 compiler_3.6.1

Running rlang::last_error() gives

  1. stop(fallback)
  2. signal_abort(cnd)
  3. cnd_signal(cnd)
  4. value[3L]
  5. tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), names[nh], parentenv, handlers[[nh]])
  6. tryCatchList(expr, classes, parentenv, handlers)
  7. tryCatch(force(expr), vctrs_error_names_cannot_be_empty = function(cnd) {cnd <- error_column_names_cannot_be_empty(detect_empty_names(name), parent = cnd) cnd$body <- details ...
  8. subclass_name_repair_errors(name = name, details = details, vec_as_names(name, repair = .name_repair, quiet = quiet || !is_character(.name_repair))) 14.repaired_names(names2(x), .name_repair = .name_repair, quiet = quiet) 13.set_names(x, repaired_names(names2(x), .name_repair = .name_repair, quiet = quiet)) 12.set_repaired_names(output, .name_repair = .name_repair) 11.tibble_quos(xs[!is_null], .rows, .name_repair) 10.tibble(!!!.x) 9.FUN(X[[i]], ...) 8.lapply(.x, .f, ...) 7.map(dots, function(.x) if (is.data.frame(.x)) .x else tibble(!!!.x)) 6.dplyr::bind_rows(res, .id = .id) 5.purrr::map_df(.x = var.ind, .f = ~vars.univariate[.]) 4.eval(lhs, parent, parent) 3.eval(lhs, parent, parent) 2.purrr::map_df(.x = var.ind, .f = ~vars.univariate[.]) %>% tidyr::gather(data = .) 1.compare_covariates(extrapolation.type = "both", covariate.names = my_cov, n.covariates = NULL, segments = segs, prediction.grid = predgrid, coordinate.system = my_crs, create.plots = TRUE, display.percent = TRUE)
pjbouchet commented 4 years ago

I was unable to replicate this issue, but have added your suggested correction to the unlist() function. Thank you for the contribution!