Skip to content

Error in selectlocs_chem(): key duplication in spread() result #120

Description

@florisvdh

This was found while doing some testing for issue #116. When running the code of the 'v210_chem' vignette, following error occurred in selectlocs_chem() code:

> myresult <-
    mydata %>%
    selectlocs_chem(
      data_type = "data",
      chem_var = c("N-NO3", "P-PO4"),
      conditions = conditions_df
    )
Error in `spread()`:
! Each row of output must be identified by a unique combination of keys.Keys are shared for 8 rows300, 301375, 376303, 304378, 379
Run `rlang::last_trace()` to see where the error occurred.
Session info
> sessioninfo::session_info()
─ Session info ──────────────────────────────────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.5.3 (2026-03-11)
 os       Linux Mint 22.3
 system   x86_64, linux-gnu
 ui       RStudio
 language nl_BE:nl
 collate  nl_BE.UTF-8
 ctype    nl_BE.UTF-8
 tz       Europe/Brussels
 date     2026-03-30
 rstudio  2026.01.1+403 Apple Blossom (desktop)
 pandoc   3.1.3 @ /usr/bin/pandoc
 quarto   1.8.25 @ /usr/lib/rstudio/resources/app/bin/quarto/bin/quarto

─ Packages ──────────────────────────────────────────────────────────────────────────────────────────────────
 ! package     * version    date (UTC) lib source
   assertthat    0.2.1      2019-03-21 [1] RSPM (R 4.4.0)
   bit           4.6.0      2025-03-06 [1] RSPM (R 4.4.0)
   bit64         4.6.0-1    2025-01-16 [1] RSPM (R 4.4.0)
   blob          1.3.0      2026-01-14 [1] CRAN (R 4.5.2)
   cachem        1.1.0      2024-05-16 [1] RSPM (R 4.4.0)
   cli           3.6.5      2025-04-23 [1] RSPM (R 4.4.0)
   DBI           1.3.0      2026-02-25 [1] CRAN (R 4.5.2)
   dbplyr        2.5.2      2026-02-13 [3] CRAN (R 4.5.2)
   desc          1.4.3      2023-12-10 [1] RSPM (R 4.4.0)
   devtools      2.5.0      2026-03-14 [1] CRAN (R 4.5.2)
   dplyr       * 1.2.0      2026-02-03 [1] CRAN (R 4.5.2)
   ellipsis      0.3.2      2021-04-29 [1] RSPM (R 4.4.0)
   fastmap       1.2.0      2024-05-15 [1] RSPM (R 4.4.2)
   fs            2.0.1      2026-03-24 [1] CRAN (R 4.5.3)
   generics      0.1.4      2025-05-09 [1] RSPM (R 4.5.0)
   glue          1.8.0      2024-09-30 [1] RSPM (R 4.4.2)
   hms           1.1.4      2025-10-17 [1] RSPM (R 4.5.0)
   inbodb        0.0.7      2025-09-08 [1] https://inbo.r-universe.dev (R 4.5.1)
   lifecycle     1.0.5      2026-01-08 [1] CRAN (R 4.5.2)
   lubridate     1.9.5      2026-02-04 [1] CRAN (R 4.5.2)
   magrittr      2.0.4      2025-09-12 [1] RSPM (R 4.5.0)
   memoise       2.0.1      2021-11-26 [1] RSPM (R 4.4.0)
   odbc          1.6.4.1    2025-12-24 [1] CRAN (R 4.5.2)
   otel          0.2.0      2025-08-29 [1] RSPM (R 4.5.0)
   pillar        1.11.1     2025-09-17 [1] RSPM (R 4.5.0)
   pkgbuild      1.4.8      2025-05-26 [1] RSPM (R 4.5.0)
   pkgconfig     2.0.3      2019-09-22 [1] RSPM (R 4.4.0)
   pkgload       1.5.0      2026-02-03 [1] CRAN (R 4.5.2)
   purrr         1.2.1      2026-01-09 [1] CRAN (R 4.5.2)
   R6            2.6.1      2025-02-15 [1] RSPM (R 4.4.0)
   Rcpp          1.1.1      2026-01-10 [1] CRAN (R 4.5.2)
   rlang         1.1.7      2026-01-09 [1] CRAN (R 4.5.2)
   rprojroot     2.1.1      2025-08-26 [1] RSPM (R 4.5.0)
   rstudioapi    0.18.0     2026-01-16 [1] CRAN (R 4.5.2)
   sessioninfo   1.2.3      2025-02-05 [1] RSPM (R 4.4.0)
   stringi       1.8.7      2025-03-27 [1] RSPM (R 4.4.0)
   stringr       1.6.0      2025-11-04 [1] RSPM (R 4.5.0)
   tibble        3.3.1      2026-01-11 [1] CRAN (R 4.5.2)
   tidyr         1.3.2      2025-12-19 [1] CRAN (R 4.5.2)
   tidyselect    1.2.1      2024-03-11 [1] RSPM (R 4.4.0)
   timechange    0.4.0      2026-01-29 [1] CRAN (R 4.5.2)
   usethis       3.2.1      2025-09-06 [1] RSPM (R 4.5.0)
   utf8          1.2.6      2025-06-08 [1] RSPM (R 4.5.0)
   vctrs         0.7.2      2026-03-21 [1] CRAN (R 4.5.3)
 P watina      * 0.4.2.9000 2026-03-30 [?] load_all()
   withr         3.0.2      2024-10-28 [1] RSPM (R 4.4.0)

 [1] /home/floris/lib/R/library
 [2] /usr/local/lib/R/site-library
 [3] /usr/lib/R/site-library
 [4] /usr/lib/R/library

 * ── Packages attached to the search path.
 P ── Loaded and on-disk path mismatch.

This points at duplicate entries being generated where they should not occur.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions