Skip to content

Commit b0b7304

Browse files
committed
added error check for unique obs id in format_model_data
1 parent e4e335d commit b0b7304

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

R/format_model_data.R

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ format_model_data <- function(project,
8383
name,
8484
alt_name,
8585
zone_id,
86-
unique_obs_id,
86+
unique_obs_id, # ADD ERROR CHECK
8787
select_vars = NULL,
8888
aux_data = NULL,
8989
aux_key = NULL,
@@ -116,6 +116,13 @@ format_model_data <- function(project,
116116
# Format main data ------------------------------------------------------------------------------
117117
# Load main data table
118118
original_dataset <- table_view(paste0(project, "MainDataTable"), project)
119+
120+
# Check unique_obs_id
121+
if (!(nrow(unique(original_dataset[unique_obs_id])) == nrow(original_dataset))) {
122+
stop("The unique_obs_id is not unique for each observation (row). Select a new variable
123+
or create a new ID variable unique to each observation.")
124+
}
125+
119126
# Load alternative choice list
120127
alt_list_all <- unserialize_table(paste0(project, "AltMatrix"), project)
121128

0 commit comments

Comments
 (0)