gpt4 book ai didi

r - 在文档对象中发现错误的\usage 行

转载 作者:行者123 更新时间:2023-12-04 12:48:48 26 4
gpt4 key购买 nike

我无法让我的包裹通过 R CMD 检查。我正在使用 devtools版本 1.9.1 和 Roxygen2版本 4.1.1。我遇到的问题如下:

Bad \usage lines found in documentation object 'my_fn':


Functions with \usage entries need to have the appropriate \alias
entries, and all their arguments documented.
The \usage entries must correspond to syntactically valid R code.
See chapter 'Writing R documentation files' in the 'Writing R
Extensions' manual.

因此,正如您所看到的,它实际上并没有给我任何有关问题发生位置的指示。它只是2个空格。

我的功能如下:
#' My function
#'
#' Extracts data from the database in order to produce plots and
#' descriptive statistics.
#'
#' @param operate A vector of ID codes.
#' @param crl A vector of crl data.
#' @param nt A vector of nt data.
#' @param ref.coef Reference coefficient for gestational age.
#' @param ... Further arguments passed to or from other methods.
#'
#' @export
my_fn <- function (operate,
crl,
nt,
ref.coef = list(fit = function(crl) {
-1 + 0.05 * crl - 0.0002 * crl ^ 2
},
sd.reg = 0.5),
...) {
# Some cool stuff
}

对应的.Rd文件如下:
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/my_fn.R
\name{my_fn}
\alias{my_fn}
\title{My function}
\usage{
my_fn(operate, crl, nt,
ref.coef = list(fit = function(crl) { -1 + 0.05 * crl - 0.0002
* crl^2 }, sd.reg = 0.5), ...)
}
\arguments{
\item{operate}{A vector of ID codes.}

\item{crl}{A vector of crl data.}

\item{nt}{A vector of nt data.}

\item{ref.coef}{Reference coefficient for gestational age.}

\item{...}{Further arguments passed to or from other methods.}
}
\description{
Extracts data from the database in order to produce plots and
descriptive statistics.
}

任何想法失败的地方?

最佳答案

当我删除整个 ref.coef从文档和功能来看,没有错误。

当我将它保存在 roxygen 文档和函数中时,对其进行 roxygenize,然后尝试添加 sd.reg (看看它是否只是一个解析错误)它仍然发出呜呜声。

它看起来不像是 Roxygen 问题,但更像是 R CMD check正在处理 Rd 文件。

临时解决方案可能是执行以下操作:

ref.coef = REF.COEF(),

进而
REF.COEF <- function() {
list(fit = function(crl) {
-1 + 0.05 * crl - 0.0002 * crl ^ 2
},
sd.reg = 0.5)
}

(因此您获得良好/通过 R CMD check 并且仍然获得您需要的功能)

并在 R 开发列表上发布关于您的错误的消息。这可能是一个简单的 Rd 解析问题(但您可能还想考虑稍微简化一下函数参数并在函数与参数中进行列表分配)。

关于r - 在文档对象中发现错误的\usage 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33390521/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com