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

roxygen2 7.1.1报@return括号或引号不匹配错误如何解决?

问题原因

你遇到的报错是Shim_local条目里的%%符号导致的:roxygen2 中%属于注释标识符,单个%就会将该行%之后的所有内容标记为注释不参与解析,你写的%%直接注释掉了该条目的闭合花括号、后续所有\item条目以及\describe的闭合花括号,最终出现语法结构不完整的报错,生成的Rd文件\value字段为空。

解决方法

方法1:转义百分号(适配roxygen2 7.1.1版本,无需修改其他配置)

将(in %%)修改为(in \\%)即可,双重转义的百分号会被roxygen2正确解析为Rd语法里的百分号符号,修改后的代码如下:

#' @return A list with the following fields: 
#' \describe{
#' \item{ID}{The speaker / speaker + session identifier of the output}
#' \item{CPPS}{Smoothed Cepstral Peak Prominence value}
#' \item{HNR}{An Harmonic-to-noise estimate}
#' \item{Shim_local}{A (local) Shimmer measurement (in \%)}
#' \item{Shim_local_DB}{A (local) Shimmer measurement, in decibels}
#' \item{LTAS_Slope}{The slope of the Long Time Average Spectrum (in dB)}
#' \item{LTAS_Tilt}{The Long Time Average Spectrum tilt (in dB)}
#' \item{AVQI}{Acoustic Voice Quality Index summarizing the measures above}
#' }

方法2:使用markdown语法写返回值(可读性更高,也可避免转义问题)

首先在项目的DESCRIPTION文件中添加一行配置开启roxygen2的markdown支持:

Roxygen: list(markdown = TRUE)

之后可以直接用markdown列表写返回值,无需使用\describe系列Rd语法,也不需要额外转义百分号:

#' @return A list with the following fields:
#' * `ID`: The speaker / speaker + session identifier of the output
#' * `CPPS`: Smoothed Cepstral Peak Prominence value
#' * `HNR`: An Harmonic-to-noise estimate
#' * `Shim_local`: A (local) Shimmer measurement (in %)
#' * `Shim_local_DB`: A (local) Shimmer measurement, in decibels
#' * `LTAS_Slope`: The slope of the Long Time Average Spectrum (in dB)
#' * `LTAS_Tilt`: The Long Time Average Spectrum tilt (in dB)
#' * `AVQI`: Acoustic Voice Quality Index summarizing the measures above

内容的提问来源于stack exchange,提问作者Fredrik Nylén

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.06 17:27:03