在最近升级到R 3.1.1之后,当在RStudio中使用devtools :: document时(Ctrl + Shift + D),曾经给我发出旧R版本警告的内容现在会抛出此错误:
==> 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.
我用谷歌搜索并阅读了roxygen2的文档,但没有找到我的问题的解决方案。 @data是外部包中的一个插槽(" hyperSpec"),我的包中的类继承该插槽。这是定义我的类的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)
}
} )
在函数sphereLeafReflectance
中,我访问了hyperSpec对象的@data槽:也许这就是导致问题的原因。我不知道为什么错误消息似乎表明问题出现在该函数的第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
...
hyperSpec包位于DESCRIPTION文件的Depends部分,并且在NAMESPACE中导入了相同的包:
import(hyperSpec)
非常感谢任何帮助!
答案 0 :(得分:0)
我只是复制粘贴Tyler的评论使其更明显:“@”字符在示例代码中不起作用。 它使roxoygen2崩溃。
要修复它,只需加倍@
...
#' xgb.importance(agaricus.test$data@@Dimnames[[2]], 'xgb.model.dump')
而不是:
#' xgb.importance(agaricus.test$data@Dimnames[[2]], 'xgb.model.dump')