【发布时间】:2020-11-12 10:32:29
【问题描述】:
我正在尝试在用户定义函数的 3 点构造上实现 lapply。不知何故,它不起作用。
banner <- function(maintext,..., subtext = NULL) {
if(length(list(...)) > 0) {
dots <- lapply(X = list(...), FUN = function(x) tags$div(x))
} else {
dots <- ''
}
HTML(paste0(
"<div class='bannerbackground'> <h2>", maintext, "</h2>",
# If subtext specified
ifelse(!is.null(subtext), paste0("<span>", subtext, "</span>", dots, "</div>"), paste0(dots, "</div>"))
))
}
banner('T1', 'T2', 'T3', subtext = 'T4')
我期待的输出
<div class='bannerbackground'> <h2>T1</h2><span>T4</span>
<div>T2</div>
<div>T3</div>
</div>
【问题讨论】: