R에 다음 Dataframe이 있습니다.
structure(list(seq = c("-", "FRD", "FHL", "ABC", "DEF", "XYZ",
"ZZZ", "CXY"), count1 = c(969, 324, 11, 161, 185, 79, 231, 9
), seq_perc = c("49.21%", "16.46%", "0.56%", "8.18%", "9.4%",
"4.01%", "11.73%", "0.46%"), marking = c("S2", "", "S1", "NA",
"Hold", "-", "-", "-"), marking_counter = c("1708", "215",
"35", "9", "2", "-", "-", "-"), Percentage2 = c("86.74%", "10.92%",
"1.78%", "0.46%", "0.1%", "-", "-", "-"), batch_no = c("6", "7",
"-", "-", "-", "-", "-", "-"), batch_no_counter = c("1717", "200",
"52", "-", "-", "-", "-", "-"), Percentage3 = c("87.2%", "10.16%",
"2.64%", "-", "-", "-", "-", "-")), .Names = c("seq", "count1",
"seq_perc", "marking", "marking_counter", "Percentage2", "batch_no",
"batch_no_counter", "Percentage3"), row.names = c("1", "9", "14",
"20", "22", "37", "46", "338"), class = "data.frame")
mailR
라이브러리를 사용하여 이메일 본문에 첨부하는 데 사용할 수있는 HTML 테이블 형식의 데이터 프레임을 은폐하기 위해 아래에 언급 된 코드를 사용하고 있습니다.
같은 오류가 발생 Error in sass_options() : could not find function "strrep"
합니다. 또한 때때로 오류가 발생합니다.Error: could not find function "gtsave"
library(gt)
library(tibble)
library(gt)
library(stringr)
library(dplyr)
test1 <- expression(marking == "Hold" & as.numeric(str_remove(Percentage2, "%")) > 25.00)
test2 <- expression(batch_no == "8" & as.numeric(str_remove(Percentage3, "%")) > 25.00)
test3 <- expression(marking == "S3" & batch_no == "9")
newtab <-
dataframe %>%
mutate(marking = ifelse(eval(test3), paste0(marking, " (In progress)"), marking)) %>%
gt() %>%
tab_style(style = list(cell_fill(color = "lightgreen"),
cell_text(weight = "bold")),
locations = cells_column_labels(columns = 1:9)) %>%
tab_style(style = list(cell_fill(color = "yellow"),
cell_text(weight = "bold")),
locations = cells_body(columns = 1:9, rows = nrow(dataframe))) %>%
tab_style(style = list(cell_fill(color = "red"),
cell_text(color = "white", weight = "bold")),
locations = cells_body(columns = c("marking", "Percentage2"),
rows = eval(test1))) %>%
tab_style(style = list(cell_fill(color = "red"),
cell_text(color = "white", weight = "bold")),
locations = cells_body(columns = c("batch_no", "Percentage3"),
rows = eval(test2))) %>%
tab_style(style = list(cell_text(size = px(2))),
locations = cells_body(columns = c("marking"),
rows = str_detect(string = marking, pattern = "progress")))
gtsave(newtab, file = "gttable.html")
첫 번째 오류와 관련하여이 strrep()
함수는 R에 상대적으로 새로 추가 된 기능이지만 (이전 버전에서는 사용할 수 없음) 기능은 간단합니다.
strrep("ab", 3)
[1] "ababab"
직접 만들 수 있습니다.
strrep <- function(x, times) paste(rep(x, times), collapse = "")
strrep("ab", 3)
[1] "ababab"
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다