Could not write to table my_usersoil4 in database
, line 2706, in importCsv
cursor.execute(sql, tuple(line))
sqlite3.IntegrityError: UNIQUE constraint failed: my_usersoil4.SNAM
I thought this could be because I might have more than one row for a given SNAM but I check and re-checked:
dplyr::group_by(SNAM) %>%
dplyr::mutate(
completeness_score = rowSums(!is.na(across(where(is.numeric))), na.rm = TRUE)
) %>%
dplyr::slice_max(completeness_score, n = 1, with_ties = FALSE) %>%
dplyr::select(-completeness_score) %>%
dplyr::ungroup()%>%
dplyr::mutate(SNAM = trimws(toupper(SNAM))) # trim any hidden spaces
as well as:
dplyr::mutate(SNAM_trim = trimws(SNAM)) %>%
dplyr::group_by(SNAM_trim) %>%
dplyr::filter(n() > 1)
nrow(dupes)
unique(dupes$SNAM_trim)
and I get zero duplicates this way. Also I have made my user table using this dataset:
Cordeiro, Marcos R C; Lelyk, Glenn; Kröbel, Roland; Legesse, Getahun; Faramarzi, Monireh; Masud, Mohammad Badrul; McAllister, Tim (2017): Deriving Canada-wide soils dataset for use in Soil and Water Assessment Tool (SWAT) [dataset]. PANGAEA, https://doi.org/10.1594/PANGAEA.877298, Supplement to: Cordeiro, MRC et al. (2018): Deriving a dataset for agriculturally relevant soils from the Soil Landscapes of Canada (SLC) database for use in Soil and Water Assessment Tool (SWAT) simulations. Earth System Science Data, 10(3), 1673-1686, https://doi.org/10.5194/essd-10-1673-2018
which contains all Canadian soils and therefore more than I need for my study area.
I would appreciate feedback on this.
Many thanks and best wishes,
Camilla Negri