简体   繁体   English

roxygen2错误:roxygen块开始失败... @data是未知密钥

[英]roxygen2 error: Failure in roxygen block beginning … @data is an unknown key

After a recent upgrade to R 3.1.1, what used to give me a warning with the old R version now throws this error when using devtools::document in RStudio (Ctrl + Shift + D): 在最近升级到R 3.1.1之后,旧的R版本曾经给我一个警告的东西现在在RStudio(Ctrl + Shift + D)中使用devtools :: document时引发此错误:

==> devtools::document(roclets=c('rd', 'collate', 'namespace'))

Updating spectrometry documentation
Loading spectrometry
First time using roxygen2 4.0. Upgrading automatically...
Error: Failure in roxygen block beginning sphereLeafReflectance.R:1
@data is an unknown key
Execution halted

Exited with status 1.

I Googled and read the doc for roxygen2 but didn't find the solution to my problem. 我用Google搜索并阅读了roxygen2的文档,但没有找到解决我问题的方法。 @data is a slot from a class in an external package ("hyperSpec") from which classes in my package inherit. @data是来自外部程序包(“ hyperSpec”)中的类的插槽,我的程序包中的类从该插槽继承。 Here's the psr3500Spec.R file defining my class: 这是定义我的课程的psr3500Spec.R文件:

#' Constructor for objects of type 'psr3500Spec'
#'
#' @title psr3500Spec class definition
#' @aliases psr3500Spec
#' @param file Character. Filename of a valid .sed file. Mandatory
#' @param datatype Character. Type of spectral data to add to object. Possible 
#' values are: RadRef/RadTarget/Reflect. Mandatory
#' @return psr3500Spec object, inheriting from 'hyperSpec' object
#' @export
psr3500Spec <- setClass("psr3500Spec", representation(datatype = "character"), 
    contains = "hyperSpec")

#' Initialize method for objects of type 'psr3500Spec'
#'
#' @keywords internal
setMethod("initialize", "psr3500Spec", 
    function(.Object, ..., file = character(), datatype = character()) {

if(nargs() > 1) {
  if(!(file.exists(file))) 
    stop("Not a valid SED file")

  if (!(datatype %in% c("RadRef", "RadTarget", "Reflect")))
    stop("Not a valid datatype. Possible values are: RadRef/RadTarget/Reflect")

  data <- readSedData(file)
  meta <- readSedMetadata(file)
  meta$datatype <- datatype
  meta$FileName <- file

  di <- grep(datatype, names(data))
  wi <- grep("Wvl", names(data))

  .Object <- callNextMethod(.Object, data = meta, 
    spc = matrix(data[, di], nrow = 1), wavelength = data[, wi])

  switch(datatype,
    "RadRef" = {
      spclab <- paste0("Reference Radiance (", meta$Units, ")")
    },
    "RadTarget" = {
      spclab <- paste0("Target Radiance (", meta$Units, ")")
    },
    "Reflect" = {
      spclab <- "Reflectance [unitless]"
    }
  )       

  .Object@label <- list(.wavelength = paste0("Wavelength (nm)" ), 
    spc = spclab)

  return(.Object)

} else {
  .Object <- callNextMethod(.Object, ...)   
  return(.Object)
}

} ) })

In the function sphereLeafReflectance I access the @data slot of an hyperSpec object: maybe this is what causes the problem. 在函数sphereLeafReflectance我访问hyperSpec对象的@data插槽:也许这是导致问题的原因。 I don't know why the error message seems to be suggesting the problem is at line 1 in that function since documentation is at this line: 我不知道为什么错误消息似乎表明问题出在该函数的第1行,因为文档位于此行:

#' Integrating sphere leaf reflectance 
#' 
#' Calculates leaf reflectance from radiance measurements made with an 
#' integrating sphere, removing the contribution from the measured stray light
#' 
#' @param Fsr psr3500Spec object. Radiance of a target (leaf) on the sample port
#' of the sphere measured in reflectance mode
#' @param Fsw psr3500Spec object. Radiance of a reference surface measured in 
...

The hyperSpec package is in the Depends section of the DESCRIPTION file and the same package is imported in NAMESPACE: hyperSpec软件包位于DESCRIPTION文件的Depends部分中,并且相同的软件包已导入到NAMESPACE中:

import(hyperSpec)

Any help will be much appreciated! 任何帮助都感激不尽!

I just copy paste the comment of Tyler to make it more obvious: "@" character doesn't work in example code. 我只是复制粘贴Tyler的注释以使其更加明显:“ @”字符在示例代码中不起作用。 It makes roxoygen2 crash. 这会使roxoygen2崩溃。

To fix it, just double the @ 要解决此问题,只需将@

...
#' xgb.importance(agaricus.test$data@@Dimnames[[2]], 'xgb.model.dump')

Instead of: 代替:

#' xgb.importance(agaricus.test$data@Dimnames[[2]], 'xgb.model.dump')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM