Rstudio Roxygen2 @importFrom 解析函数头

标签 r rstudio rcpp roxygen2

我正在使用 Rstudio 用 Rcpp 构建一个包。一切正常,直到我将文档标记添加到我的函数文件中。我希望我忽略了一些明显的东西。

这是我的 R 函数文件:

#' @useDynLib tablr
#' @importFrom Rcpp sourceCpp
#'
#' fast.table
#'
#' C++ implementation of the R table function. Only supports numeric
#' vectors. Does not currently handle NAs.
#'
#' @param x1 Variable 1
#' @param x2 Variable 2
#' @return A table object equal in every way to an R table object with the same
#' inputs
#'
#' @export fast.table
fast.table <- function(x1, x2) {
  nms <- c(deparse(substitute(x1)), deparse(substitute(x2)))
  cpp_table(as.numeric(x1), as.numeric(x2), as.character(nms))
}

运行后devtools::document()这是命名空间文件的样子:
# Generated by roxygen2 (4.0.2): do not edit by hand

export(fast.table)
importFrom(Rcpp,"C++")
importFrom(Rcpp,Does)
importFrom(Rcpp,NAs.)
importFrom(Rcpp,Only)
importFrom(Rcpp,R)
importFrom(Rcpp,currently)
importFrom(Rcpp,fast.table)
importFrom(Rcpp,function.)
importFrom(Rcpp,handle)
importFrom(Rcpp,implementation)
importFrom(Rcpp,not)
importFrom(Rcpp,numeric)
importFrom(Rcpp,of)
importFrom(Rcpp,sourceCpp)
importFrom(Rcpp,supports)
importFrom(Rcpp,table)
importFrom(Rcpp,the)
importFrom(Rcpp,vectors.)
useDynLib(tablr)

如您所见,@importFrom标签正在解析函数标题文本并尝试从 Rcpp 导入每个“单词”包裹。

运行后的错误信息devtools::document() :
Error: object 'C++' is not exported by 'namespace:Rcpp'
Execution halted

Exited with status 1.

和 session 信息:
> devtools::session_info()
Session info----------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.1.1 (2014-07-10)
 system   x86_64, mingw32             
 ui       RStudio (0.98.1049)         
 language (EN)                        
 collate  English_United States.1252  
 tz       America/Chicago             

Packages--------------------------------------------------------------------------------------
 package    * version date       source        
 devtools     1.6.1   2014-10-07 CRAN (R 3.1.1)
 Rcpp         0.11.3  2014-09-29 CRAN (R 3.1.1)
 roxygen2     4.0.2   2014-09-02 CRAN (R 3.1.1)
 rstudioapi   0.1     2014-03-27 CRAN (R 3.1.1)
 stringr      0.6.2   2012-12-06 CRAN (R 3.1.0)
 tablr      * 0.1     <NA>       local         

最佳答案

通过在 @importFrom 之后放置 NULL 来解决标签:

#' @useDynLib tablr
#' @importFrom Rcpp sourceCpp
NULL

#' fast.table
#'
#' C++ implementation of the R table function. Only supports numeric
#' vectors. Does not currently handle NAs.
#'
#' @param x1 Variable 1
#' @param x2 Variable 2
#' @return A table object equal in every way to an R table object with the same
#' inputs
#'
#' @export fast.table
fast.table <- function(x1, x2) {
  nms <- c(deparse(substitute(x1)), deparse(substitute(x2)))
  cpp_table(as.numeric(x1), as.numeric(x2), as.character(nms))
}

关于Rstudio Roxygen2 @importFrom 解析函数头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26386811/

相关文章:

c++ - Rcpp C/C++ 使用结构和 char*

r - 关于data.table 1.9.2的新特征J()

r - 如何将多个文件加载到 R 中而不覆盖现有文件?

r - ggplot2时间序列数据在R中显示不稳定的线

r - 无法使用 h2o.init() 连接到 R 中的 h20

从压缩文件和已知起始位置(字节偏移)读取 R 中的二进制文件

r - ggplot2 和 map : geom_point and annotation_raster position mismatch

r - 无法安装最新版本的 R 包

r - Knitr:spin - 如何添加文本而不手动添加 #' 每行?

c++ - 如何使用 Rcpp 就地缩放 NumericMatrix?