3

Given a dataframe df as follows:

df <- structure(list(class = c("A", "", "", "B", ""), name = c("Jack", 
"Rose", "Steve", "James", "Rick"), score = c(7L, 18L, 9L, 15L, 
12L)), class = "data.frame", row.names = c(NA, -5L))

Is it possible I get the output effect as follows with formattable:

enter image description here

library(df)
formattable(df)

Out:

enter image description here

Updated code:

library(flextable)

data <- flextable(
  df, 
  col_keys = c("class", "name", "score"))
data <- merge_v(data, j = c("class"))
formattable(data)

Out:

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

It raises same error as above:

library(gt)

# dummy data
dat <- tibble(
  a=1:3,
  b=c("a","b c","d e f")
)

d <- dat %>% 
  mutate(b = str_replace_all(b, " ", "<br>")) %>% 
  gt() %>% 
  fmt_markdown(columns = TRUE)

formattable(d)

Code which may help:

a1 <- c(1, 2, 3)
data <- c(100, 155, -4)
a2 <- c(0, paste(data, collapse = "<br> "), 1000000) 
b <- data.frame(cbind(a1, a2))
width <- 10

formattable(b)

Out:

enter image description here

Reference:

In R when using formattable() place line breaks between entries inside a single cell

ah bon
  • 9,293
  • 12
  • 65
  • 148
  • 1
    I like to use `flextable` for that. Should you not easily find a `formattable` solution see https://mran.microsoft.com/snapshot/2020-01-11/web/packages/flextable/vignettes/overview.html – Bernhard Oct 12 '21 at 08:15
  • I try to use `merge_v` from `flextable` then use `formattable`, seems not working. – ah bon Oct 12 '21 at 08:34
  • 1
    Related post: https://stackoverflow.com/q/63354827/680068 – zx8754 Oct 12 '21 at 08:44
  • Thanks, but I need to use `formattable` or apply it to data after merged using other packes since the major part of my code is realized with `formattable` . Is it possible? – ah bon Oct 12 '21 at 08:51

0 Answers0