首页 > 解决方案 > Rcpp 在两个函数之间共享相同的 roxygen

问题描述

考虑以下函数:

//' Provides some stuff AB
//' @param a integer that responsible for stuff A
//' @param b integer that responsible for stuff B
//' @export
// [[Rcpp::export]]
NumericVector foo1(int a, int b)
{
   //some code
}

//' Provides some stuff AC
//' @param a integer that responsible for stuff A
//' @param c integer that responsible for stuff C
//' @export
// [[Rcpp::export]]
NumericVector foo2(int a, int c)
{
   //some code
}

请注意,对于 foo1 和 foo2,参数a 的描述应该相同。我有许多功能,应该以相同的方式提供参数描述每次我分别为每个函数需要它时,我都不想复制过去的参数描述。是否可以指定描述并将其应用于我的 Rcpp 包提供的所有功能?

将非常感谢您的帮助!

标签: rrcpproxygen2roxygenrcpp11

解决方案


感谢 Dirk Eddelbuettel,我找到了答案:

//' @name sharable
//' @rdname sharable
//' @param a integer that responsible for stuff A
//' @export

//' Provides some stuff AB
//' @rdname sharable
//' @param b integer that responsible for stuff B
//' @export
// [[Rcpp::export]]
NumericVector foo1(int a, int b)
{
   //some code
}

//' Provides some stuff AC
//' @rdname sharable
//' @param c integer that responsible for stuff C
//' @export
// [[Rcpp::export]]
NumericVector foo2(int a, int c)
{
   //some code
}

推荐阅读