From 8ad50eb17668bc8bd0f837d87f0b0ff0f9ea4f59 Mon Sep 17 00:00:00 2001 From: Admin_mschuemi Date: Thu, 23 May 2024 06:19:28 -0400 Subject: [PATCH] Preventing duplicate calendar time and age knots, causing unique key violation errors when uploading. --- NEWS.md | 2 ++ R/SccsDataConversion.R | 2 ++ 2 files changed, 4 insertions(+) diff --git a/NEWS.md b/NEWS.md index 41b8e81..1386d30 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,6 +11,8 @@ Bugfixes 2. Fixed case count in `createStudyPopulation()` when restricting time in prior `getDbSccsData()` call, e.g. by defining a study period and/or nesting cohort. +3. Preventing duplicate calendar time and age knots, causing unique key violation errors when uploading. + SelfControlledCaseSeries 5.1.1 ============================== diff --git a/R/SccsDataConversion.R b/R/SccsDataConversion.R index 65039df..51fb9b7 100644 --- a/R/SccsDataConversion.R +++ b/R/SccsDataConversion.R @@ -215,6 +215,7 @@ addAgeSettings <- function(settings, transmute(outcomeAge = .data$outcomeDay + .data$ageAtObsStart) %>% pull() %>% quantile(seq(0.01, 0.99, length.out = ageCovariateSettings$ageKnots)) + ageKnots <- ageKnots[!duplicated(ageKnots)] } else { ageKnots <- ageCovariateSettings$ageKnots } @@ -328,6 +329,7 @@ addCalendarTimeSettings <- function(settings, for (j in seq_len(knotsInPeriod)) { calendarTimeKnots[j] <- min(countsInPeriod$month[countsInPeriod$cumCount >= cutoffs[j]]) } + calendarTimeKnots <- calendarTimeKnots[!duplicated(calendarTimeKnots)] calendarTimeKnotsInPeriods[[length(calendarTimeKnotsInPeriods) + 1]] <- calendarTimeKnots } } else {