Error in create_obj - argument "formatter" is missing, with no default

Hi Community,

I want to apply this code to a list of similar dataframes - DATAFRAMES_2[i] - instead of to a single dataframe - scores

formattable(scores, list(
  prev_score = formatter("span", 
                         style = ~style(display = "block",
                                        font.weight = "bold", 
                                        color = "white",
                                        "border-radius" = "4px",
                                        "padding-right" = "4px",
                                        "background-color" =  
                                          ifelse(change > 0,"darkblue",
                                                 ifelse(change == 0,"blue",
                                                        ifelse(change <0, "lightblue",NA)))))

I tried to use this code:

for(i in 1:length(DATAFRAMES_2)) {
  formattable(DATAFRAMES_2[i], list(
    Casa = formatter("span", 
                     style = ~style(display = "block",
                                    font.weight = "bold", 
                                    color = "white",
                                    "border-radius" = "4px",
                                    "padding-right" = "4px",
                                    "background-color" =  
                                      ifelse(Casa %in% CLUBES_CASA,"chartreuse4",NA)))))  
}

But I got this erroe message:

Error in create_obj(x, "formattable", list(formatter = formatter, format = list(...),  : 
  argument "formatter" is missing, with no default

Can you help me please?

assuming that DATAFRAMES_2 is a list, to access one of its contents directly use double square brackets; this returns it unwrapped. using single square brackets as you did gives you the information 'wrapped' i.e. in a list. a list size of 1 but a list none the less
consider this simple example

list(a=1,b=2)[1]
list(a=1,b=2)[[1]]

@nirgrahamuk

Instead of

DATAFRAMES_2[i]

I wrote

DATAFRAMES_2[[i]]

and I got the same error.

This runs without errors for me.

library(formattable)

DATAFRAMES_2 <- list(
  data.frame(
    Casa = c("x", "y"),
    CLUBES_CASA = rep("y", 2)
  ),
  data.frame(
    Casa = c("x", "y"),
    CLUBES_CASA = rep("x", 2)
  )
)

for (i in 1:length(DATAFRAMES_2)) {
  formattable(DATAFRAMES_2[[i]], list(
    Casa = formatter("span",
      style = ~ style(
        display = "block",
        font.weight = "bold",
        color = "white",
        "border-radius" = "4px",
        "padding-right" = "4px",
        "background-color" =
          ifelse(Casa %in% CLUBES_CASA,
                 "#458B00", "white")
      )
    )
  )) |>
    print()
}

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.