rcaaqs
rcaaqs copied to clipboard
get_labels function error
The following error appears when running pm_annual_caaqs() is executed:
Error in cut.default(x, breaks = breaks, labels = labels, ordered_result = TRUE, : lengths of 'breaks' and 'labels' differ
Close inspection on the code shows the error is due to the get_labels() in cut.R. labels and breaks appear to have incompatible number of elements. Suggested fix to the cut.R below, which adds a lower value for labels
get_labels <- function(x, output, drop_na) {
if (!output %in% c("labels", "breaks_h", "breaks_u", "colour", "color")) {
stop(output, " is not a valid input for output. It must be either 'labels',",
"'breaks_u' (for unicode encoding), 'breaks_h' (for html encoding)",
" or 'colour' to get hexadecimal colour codes")
}
if (output == "labels") {
labels <- x[["labels"]]
} else if (output == "breaks_u") {
labels <- x[["val_labels_unicode"]]
} else if (output == "breaks_h") {
labels <- x[["val_labels_html"]]
} else if (output %in% c("colour", "color")) {
labels <- x[["colour"]]
}
labels <- c(NA,labels) #added bug fix - JAR 20220811
labels <- factor(labels, levels = labels, ordered = TRUE)
if(drop_na) labels <- droplevels(labels[-1])
if(output == "labels") labels else as.character(labels)
}