Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_labels function error #60

Open
jeromerobles opened this issue Aug 11, 2022 · 0 comments
Open

get_labels function error #60

jeromerobles opened this issue Aug 11, 2022 · 0 comments

Comments

@jeromerobles
Copy link

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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant