Error in mapply(FUN = f, ..., SIMPLIFY = FALSE) : zero-length inputs cannot be mixed with those of non-zero length

Hi all ! I am trying to create a geom extension. I have the following issue :

I expected setup_data to add the required_aes in the data and then pass it to draw_group
but the setup_data method fails as it enters draw_group method and throws the above mentioned error.

Please offer some suggestions !

the data after setup_params looks like this

The data just before setup_data finishes

What the data should like : what data should look like after setup_data as it enters draw_group

GeomRbar <- ggplot2::ggproto("GeomRbar", ggplot2::Geom,
  required_aes = c("x", "y"),
  default_aes = ggplot2::aes(
    fill = "grey60",
    size = 1.25,
    colour_inner_circle = "grey90",
    standard_error = TRUE

  setup_data = function(data, params) {

    data <- data %>%
      dplyr::mutate(.cluster = params$cluster_assignment) %>%
      dplyr::mutate(feature_groups = params$group_names)

    if (!is.null(params$cluster_phase)) {
      data <- data %>% dplyr::mutate(.phase = params$cluster_phase)
    } else {
      data <- data %>% dplyr::mutate(.phase := NA_character_)

    if (!is.null(params$unique_id)) {
      data <- data %>% dplyr::mutate(.id = params$unique_id)
    } else {
      data <- data %>% mutate(.id := NA_character_)

    vars_dummy <- setdiff(c(".phase", ".id", ".cluster", "feature_groups"), names(data))

    if (length(vars_dummy) > 0) {
      rlang::abort("Data doesn't have required structure to build the plot")

    ####  Calculate cluster average for each feature
    if (!is.null(params$cluster_idx)) {
      rlang::inform("Calculating cluster average for each feature")

      data <- data %>% dplyr::filter(.cluster == levels(.cluster)[params$cluster_idx]) # now contains observations from one cluster(cluster of interest) e.g C2 has 23713 observations

    if (!is.null(params$cluster_idx)) {
      data <- data %>%
        dplyr::mutate(.cluster = forcats::fct_drop(as.factor(.cluster))) %>% # fct_drop - drops unused levels
        dplyr::mutate(.cluster = factor(.cluster, labels = paste(params$cluster_abbrev, levels(.cluster)))) # add cluster_abbrev to .cluster e.g : PT C2
    } else {
      data <- data

  # draw_group ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  draw_group = function(data, params, cluster_idx = NULL,
                        cluster_assignment = NULL,
                        phase_present = FALSE,
                        cluster_phase = NULL,
                        cluster_name = NULL,
                        cluster_abbrev = NULL,
                        colour_clusters = NULL,
                        scale_rng = c(-1, 1) * 1.5,
                        data_dict = NULL,
                        delta_threshold = 0.25,
                        group_names = NULL,
                        show_group_names = FALSE,
                        unique_id = NULL,
                        na.rm = FALSE) {
    data_check <- data


Can you include a full reprex, so we can reproduce and troubleshoot? (It's also very hard to read from screenshots).

There's a nice FAQ on how to do a minimal reprex for beginners, below:

For pointers specific to the community site, check out the reprex FAQ.

In this case I need to provide the code until the data reaches the draw_group method??

Or at least a copy-paste-able sample of the data after setup_params. You don't need the whole thing, and it's possible that someone who knows custom geoms better could look at your code and tell you what's wrong without needing to reproduce it. But, you'll broaden the population of people who can help you if you give us something we can run and test.

Removing this thread because Ashish Soni created a new topic which includes sample data for the reprex