You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

提交R包至CRAN遭遇HTML验证问题,求解决方案

解决CRAN提交时HTML手册验证NOTE的思路

问题场景

提交R包至CRAN时,运行devtools::check(remote = TRUE, manual = TRUE)触发以下HTML验证NOTE:

checking HTML version of manual ... NOTE
  Found the following HTML validation problems:
  plot_interactive.html:15:44 (plot_interactive.Rd:5): Error: <main> is not recognized!
  plot_interactive.html:15:44 (plot_interactive.Rd:5): Warning: discarding unexpected <main>
  plot_interactive.html:74:1 (plot_interactive.Rd:37): Warning: discarding unexpected </main>
  plot_interactive.html:4:1 (plot_interactive.Rd:5): Warning: <link> inserting "type" attribute
  plot_interactive.html:12:1 (plot_interactive.Rd:5): Warning: <script> proprietary attribute "onload"
  plot_interactive.html:12:1 (plot_interactive.Rd:5): Warning: <script> inserting "type" attribute
  plot_interactive.html:17:1 (plot_interactive.Rd:5): Warning: <table> lacks "summary" attribute
  plot_interactive.html:38:1 (plot_interactive.Rd:10): Warning: <table> lacks "summary" attribute
  start_gui.html:15:44 (start_gui.Rd:5): Error: <main> is not recognized!
  start_gui.html:15:44 (start_gui.Rd:5): Warning: discarding unexpected <main>
  start_gui.html:75:1 (start_gui.Rd:37): Warning: discarding unexpected </main>
  start_gui.html:4:1 (start_gui.Rd:5): Warning: <link> inserting "type" attribute
  start_gui.html:12:1 (start_gui.Rd:5): Warning: <script> proprietary attribute "onload"
  start_gui.html:12:1 (start_gui.Rd:5): Warning: <script> inserting "type" attribute
  start_gui.html:17:1 (start_gui.Rd:5): Warning: <table> lacks "summary" attribute
  start_gui.html:35:1 (start_gui.Rd:10): Warning: <table> lacks "summary" attribute

已尝试操作

  • 升级roxygen2至7.3.2版本
  • 升级R至4.4.1版本
  • 重新运行devtools::document()

解决思路

1. 替换/移除不兼容的HTML5标签

CRAN的HTML验证基于旧版HTML规范,不支持<main>这类HTML5新增标签。检查start_gui.R和plot_interactive.R中的roxygen注释,找到手动插入的<main>和</main>标签:

  • 若仅用于布局,可替换为<div>标签
  • 若为冗余结构,直接删除即可

错误提示中的<link>和带onload属性的<script>属于手动插入的冗余内容:

  • CRAN手册生成流程会自动处理样式和基础脚本,无需手动引入外部样式或自定义脚本
  • 找到roxygen注释中对应的<link>、<script>代码,直接删除

3. 为HTML表格添加summary属性

针对<table> lacks "summary" attribute的警告,给roxygen注释中所有HTML表格添加summary属性,说明表格内容:

<table summary="函数参数说明表">
  <!-- 表格内容 -->
</table>

4. 清理.Rd文件缓存并重新生成

若devtools::document()未完全覆盖旧内容:

  • 先运行devtools::clean_docs()删除已生成的.Rd文件
  • 再重新运行devtools::document()确保生成全新的.Rd文件
  • 检查生成的start_gui.Rd和plot_interactive.Rd,确认无残留的非法HTML标签

5. 确认roxygen2版本配置

检查包的DESCRIPTION文件,确保RoxygenNote字段设置为7.3.2,避免使用旧版本的roxygen2生成文档。


内容的提问来源于stack exchange,提问作者Julian Karch

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 18:32:42