Puzzling “unexpected END_OF_INPUT” while building package with roxygen2

孤者浪人 提交于 2019-12-13 18:09:33

问题


I'm trying to release this package, but it keeps failing on build.

I get variations on this in both build and check:

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

I have traced the problem to a single line in the @examples for interpolateAndApplyWithinSpatial():

#' \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

The ##PROBLEMATIC LINE HERE## was originally dist.fn( points1@coords, points2@coords ), which causes the error message on package build.

If I comment out dist.fn( points1@coords, points2@coords ), it still returns an error message. If I copy and paste the code into the console, it runs. I've tried re-typing it by hand so I'm sure there's no funny character in there, and it still fails.

The .Rd file that gets generated seems to omit everything after the @, which leaves it a few } short :

\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
}

My best guess as to what's going on is that roxygen2 is interpreting @coords as a roxygen2 directive. Is that right? And if so how do I fix it? Short-term fix is to write an accessor function for the coords slot and use that, I guess.


回答1:


The symbol @ has special meaning in Roxygen. So if you need to use @ in your Roxygen example code (or in any Roxygen field, for that matter) you need to replace it with @@.

Thus, the Roxygen segment:

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

Will translate to the following code in your R man pages:

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

Note that in this case you can replace points1@coords with coordinates(points1), as observed in the comments. However, this may not always be possible, depending whether a method exists to index the slot in your S4-class object.



来源:https://stackoverflow.com/questions/23931619/puzzling-unexpected-end-of-input-while-building-package-with-roxygen2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!