【问题标题】:Puzzling "unexpected END_OF_INPUT" while building package with roxygen2使用 roxygen2 构建软件包时令人费解的“意外 END_OF_INPUT”
【发布时间】:2014-05-29 10:50:45
【问题描述】:

我正在尝试发布 this package,但它在构建时一直失败。

我在buildcheck 都得到了这方面的变化:

Warning: /tmp/RtmpUUrH6N/Rbuild51f35b160bfe/taRifx.geo/man/interpolateAndApplyWithinSpatial.Rd:66: unexpected END_OF_INPUT '

我已将问题追溯到@examplesinterpolateAndApplyWithinSpatial() 的一行:

#' \dontrun{
#' require(fields)
#' require(rgdal)
#' distanceMatrix <- function( points1, points2, dist.fn=rdist.earth ) {
#'  cat( "Generating distance matrix for ",length(points1)," by ", length(points2), " matrix.\n" )
#'  if(!is.na(proj4string(points1)))  points1 <- spTransform( points1, CRS("+proj=longlat +datum=WGS84") )
#'  if(!is.na(proj4string(points2)))  points2 <- spTransform( points2, CRS("+proj=longlat +datum=WGS84") )
#'  ##PROBLEMATIC LINE HERE##
#' }
#' } # end of dontrun

##PROBLEMATIC LINE HERE## 最初是 dist.fn( points1@coords, points2@coords ),这会导致包构建时出现错误消息。

如果我注释掉dist.fn( points1@coords, points2@coords ),它仍然会返回一条错误消息。如果我将代码复制并粘贴到控制台中,它就会运行。我试过手动重新输入,所以我确定里面没有有趣的角色,但它仍然失败。

生成的.Rd 文件似乎省略了@ 之后的所有内容,从而留下了一些} 短:

\examples{
# Not run because too time-consuming
\dontrun{
require(fields)
require(rgdal)
distanceMatrix <- function( points1, points2, dist.fn=rdist.earth ) {
 cat( "Generating distance matrix for ",length(points1)," by ", length(points2), " matrix.\\n" )
 if(!is.na(proj4string(points1)))  points1 <- spTransform( points1, CRS("+proj=longlat +datum=WGS84") )
 if(!is.na(proj4string(points2)))  points2 <- spTransform( points2, CRS("+proj=longlat +datum=WGS84") )
 dist.fn( points1
}

我最好的猜测是roxygen2@coords 解释为roxygen2 指令。那正确吗?如果是这样,我该如何解决?短期修复是为coords 插槽编写一个访问器函数并使用它,我猜。

【问题讨论】:

  • 我不确定这是否会有所帮助,但如果您使用的是最新版本 (roxygen2_4.0.1.99) 和 roxygenize(),请尝试丢弃 man 文件夹并使用来自 @987654343 的 document() @,它在工作时调用roxygen2,而不是。我不能完全说明原因,但这个工作流程确保了一组干净的Rd 文件,并且似乎比直接的roxygenize() 工作得更好/不同。它解决了我遇到的一些问题(尽管与你的不同)。
  • 也许您应该使用coordinates(points1) 而不是尝试使用@-符号访问班级成员!
  • @Spacedman 给出了(最有可能是正确的)答案,但它提醒了我:@ 是一个保留符号,所以在 Roxygen 中你应该“转义”它。在 roxygen 行中尝试 @@
  • @Spacedman 这实际上是我将其更改为:-)。旧代码.... @Andrie 谢谢。 @@ 是另一个 roxygen 问题的解决方案,现在一切都说得通了。你可以发布一个答案,我会接受吗?

标签: r roxygen2


【解决方案1】:

符号@ 在 Roxygen 中具有特殊含义。因此,如果您需要在 Roxygen 示例代码中(或在任何 Roxygen 字段中)使用 @,则需要将其替换为 @@

因此,Roxygen 段:

#' @examples
#' dist.fn( points1@@coords, points2@@coords )

将在您的 R 手册页中转换为以下代码:

dist.fn( points1@coords, points2@coords )

请注意,在这种情况下,您可以将 points1@coords 替换为 coordinates(points1),如 cmets 中所观察到的。但是,这可能并不总是可行,这取决于是否存在用于索引 S4 类对象中的插槽的方法。

【讨论】:

  • 谢谢@Andrie。我认为是sp::coordinates(),而不是coords()
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-08-23
  • 2023-03-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-01
相关资源
最近更新 更多