Skip to content

Commit

Permalink
Extract checkOrAddInspectionTime()
Browse files Browse the repository at this point in the history
  • Loading branch information
hsonne committed Nov 16, 2024
1 parent fdd3d6a commit 16b68c5
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions R/setGlobalInspectionID.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,17 @@ setGlobalInspectionID <- function(

# The following function requires the column "inspection_time". If this
# column does not exist, create it with a default value
timeColumn <- get_elements(elements = name.convention, list(
norm = "ABG",
camel = "InspTime",
snake = "inspection_time"
))

inspections[[timeColumn]] <- fillTimeVector(
x = if (timeColumn %in% names(inspections)) {
inspections[[timeColumn]]
} else {
character(nrow(inspections))
},
hhmm = default.time,
inspections <- checkOrAddInspectionTime(
data = inspections,
column = get_elements(elements = name.convention, list(
norm = "ABG",
camel = "InspTime",
snake = "inspection_time"
)),
hhmm = default.time,
seed = 123L
)

# Create the inspection IDs and store them in column "inspection_id"
hashes <- createHashFromColumns(
data = inspections,
Expand Down Expand Up @@ -93,6 +88,18 @@ setGlobalInspectionID <- function(
)
}

# checkOrAddInspectionTime -----------------------------------------------------
checkOrAddInspectionTime <- function(data, column, ...)
{
x <- if (column %in% names(data)) {
data[[column]]
} else {
character(nrow(data))
}
data[[column]] <- fillTimeVector(x, ...)
data
}

# fillTimeVector ---------------------------------------------------------------
fillTimeVector <- function(x, hhmm = "22:22", seed = NULL, silent = FALSE)
{
Expand Down

0 comments on commit 16b68c5

Please sign in to comment.