有人知道,使用R staticdocs,如何定义演示的名称?生成的html文件中的标题不反映演示00Index文件中包含的内容?
答案 0 :(得分:1)
认为演示构建例程中缺少某些东西,以下是一个标准的staticdocs的简单修改例程。基本上,应该设置pgk $ title属性,我试图在下面强调:
build_demos = function (pkg = ".") {
pkg <- staticdocs::as.sd_package(pkg)
demo_dir <- file.path(pkg$path, "demo")
if (!file.exists(demo_dir))
return()
message("Rendering demos")
demos <- readLines(file.path(demo_dir, "00Index"))
pieces <- stringr::str_split_fixed(demos, "\\s+", 2)
in_path <- stringr::str_c(pieces[, 1], ".r")
filename <- stringr::str_c("demo-", pieces[, 1], ".html")
title <- pieces[, 2]
for (i in seq_along(title)) {
demo_code <- readLines(file.path(demo_dir, in_path[i]))
demo_expr <- evaluate::evaluate(demo_code, new.env(parent = globalenv()), new_device = FALSE)
#NH: replay_html is not exported...
replay_html <- getFromNamespace('replay_html','staticdocs')
pkg$demo <- replay_html(demo_expr, pkg = pkg, name = stringr::str_c(pieces[i],"-"))
pkg$pagetitle <- title[i]
#---------------------------------------------------
#NH: Need to set the title attribute...
#---------------------------------------------------
pkg$title <- pkg$pagetitle
#---------------------------------------------------
staticdocs::render_page(pkg, "demo", pkg, file.path(pkg$site_path, filename[i]))
}
invisible(list(demo = unname(apply(cbind(filename,title), 1, as.list))))
}