如何自动化@usage
部分Rcpp
部分的文档?在使用roxygen2
记录的包中的普通R函数中,用法部分自动添加。这样可以方便地自动记录默认参数。
#' @title Hello world
#' @return Prints 'Hello world'
#' @export
#' @useDynLib RcppSandBox
hello <- function(x = 1) {
print("Hello, world!")
}
Hello world
用法
hello(x = 1)
值
打印'Hello world'
然而,当我使用Rcpp
编写类似的脚本时,会生成文档,但不会编写@usage
部分。
//' Hello, Rcpp!
//' @name rcpp_hello
//' @param CharVec Print x or not.
//' @export
#include <Rcpp.h>
using namespace Rcpp;
// This is a simple function using Rcpp that creates an R list
// containing a character vector and a numeric vector.
//
// Learn more about how to use Rcpp at:
//
// http://www.rcpp.org/
// http://adv-r.had.co.nz/Rcpp.html
//
// and browse examples of code using Rcpp at:
//
// http://gallery.rcpp.org/
//
// [[Rcpp::export]]
List rcpp_hello(bool CharVec = true) {
CharacterVector x = CharacterVector::create("foo", "bar");
NumericVector y = NumericVector::create(0.0, 1.0);
List z = List::create(x, y);
if (CharVec) {
} else {
List z = List::create(y);
}
return z;
}
您好,Rcpp!
描述
您好,Rcpp!
参数
CharVec
是否打印x。
我查看了dplyr::between
的源代码和文档,但似乎没有任何特殊的@usage
部分,但文档中提供了@usage
部分。
我还查看了http://r-pkgs.had.co.nz/man.html和http://dirk.eddelbuettel.com/code/rcpp/Rcpp-attributes.pdf以及Ctrl-F
'd的使用情况,但没有发现任何相关内容。
我知道我可以在这个特殊情况下添加//' @usage rcpp_hello(CharVec = TRUE)
,但让roxygen2
自动化过程的好处是我可以更改默认参数。
Package: RcppSandBox
Type: Package
Title: What the Package Does (Title Case)
Version: 0.1.0
Author: Who wrote it
Maintainer: The package maintainer <yourself@somewhere.net>
Description: More about what it does (maybe more than one line)
Use four spaces when indenting paragraphs within the Description.
License: What license is it under?
Encoding: UTF-8
LazyData: true
Imports: Rcpp (>= 0.12.10)
LinkingTo: Rcpp
RoxygenNote: 6.0.1
> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_Australia.1252 LC_CTYPE=English_Australia.1252 LC_MONETARY=English_Australia.1252
[4] LC_NUMERIC=C LC_TIME=English_Australia.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] RcppSandBox_0.1.0 dplyr_0.5.0 RevoUtilsMath_10.0.0
loaded via a namespace (and not attached):
[1] compiler_3.4.0 magrittr_1.5 R6_2.2.2 assertthat_0.2.0 RevoUtils_10.0.4 DBI_0.6-1 tools_3.4.0
[8] tibble_1.3.0 Rcpp_0.12.10
答案 0 :(得分:2)
您不需要使用@usage
,因为Roxygen2 2.0和3.0.0用于 R 或 Rcpp 。您遇到的问题是您的roxygen标记不直接位于Rcpp属性标记之上...
#include <Rcpp.h>
//' Hello, Rcpp!
//' @param CharVec Print x or not.
//' @export
// [[Rcpp::export]]
Rcpp::List rcpp_hello(bool CharVec = true) {
Rcpp::CharacterVector x = Rcpp::CharacterVector::create("foo", "bar");
Rcpp::NumericVector y = Rcpp::NumericVector::create(0.0, 1.0);
Rcpp::List z = Rcpp::List::create(x, y);
if (CharVec) {
} else {
Rcpp::List z = Rcpp::List::create(y);
}
return z;
}
尝试以上方法。这也意味着您不需要@name
标记......