RcppTN .cpp 脚本在获取时有效,但在库中编译时无效
RcppTN .cpp script works when sourced but not when compiled in library
我正在尝试创建一个 R 程序包,它使用 .cpp 脚本中的截断法线随机抽取。我正在使用 pckage RcppTN 中的 rtn1 函数。如果我获取代码,该功能可以正常工作。构建包后,出现错误:
> library(testtruncnorm)
> testtruncnorm()
Error in testtruncnorm::testtruncnorm() :
function 'RcppTN_rtn1' not provided by package 'RcppTN'
这里有简化的 .cpp 代码
#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
#include <RcppTN.h>
// [[Rcpp::depends(RcppTN)]]
#include<armadillo>
using namespace Rcpp;
//' draw truncated normal
//'
//' testtruncnorm()
//' @return returns 2 draws from a truncated normal
// [[Rcpp::export]]
arma::vec testtruncnorm()
{
arma::vec result = arma::ones(2);
result[1] = RcppTN::rtn1(1, 1, 0,HUGE_VAL);
result[2] = RcppTN::rtn1(1, 1, 0,HUGE_VAL);
return result;
}
我的命名空间文件是
useDynLib(testtruncnorm, .registration=TRUE)
importFrom(Rcpp, evalCpp)
exportPattern("^[[:alpha:]]+")
我的 DESCRIPTION 文件是
Package: testtruncnorm
Type: Package
Title: What the Package Does Using Title Case
Version: 1.0
Date: 2018-10-23
Author: Your Name
Maintainer: Your Name <your@email.com>
Description: More details about what the package does. See
<http://cran.r-project.org/doc/manuals/r-release/R-exts.html#The-
DESCRIPTION-file>
for details on how to write this part.
License: GPL (>= 2)
Imports: Rcpp (>= 0.12.19), RcppTN
LinkingTo: Rcpp, RcppArmadillo, RcppTN
我正在使用 RStudio create "R Package with RcppArmadillo" 开始。 RStudio 版本 1.1.456。 R 版本 3.5.1。 Windows10.
您必须确保 RcppTN
已附加。您可以使用
importFrom(RcppTN, rtn)
在 NAMESPACE
中。在 RcppTN
的文档中说应该添加
Depends: RcppTN
应该是一样的效果
我正在尝试创建一个 R 程序包,它使用 .cpp 脚本中的截断法线随机抽取。我正在使用 pckage RcppTN 中的 rtn1 函数。如果我获取代码,该功能可以正常工作。构建包后,出现错误:
> library(testtruncnorm)
> testtruncnorm()
Error in testtruncnorm::testtruncnorm() :
function 'RcppTN_rtn1' not provided by package 'RcppTN'
这里有简化的 .cpp 代码
#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
#include <RcppTN.h>
// [[Rcpp::depends(RcppTN)]]
#include<armadillo>
using namespace Rcpp;
//' draw truncated normal
//'
//' testtruncnorm()
//' @return returns 2 draws from a truncated normal
// [[Rcpp::export]]
arma::vec testtruncnorm()
{
arma::vec result = arma::ones(2);
result[1] = RcppTN::rtn1(1, 1, 0,HUGE_VAL);
result[2] = RcppTN::rtn1(1, 1, 0,HUGE_VAL);
return result;
}
我的命名空间文件是
useDynLib(testtruncnorm, .registration=TRUE)
importFrom(Rcpp, evalCpp)
exportPattern("^[[:alpha:]]+")
我的 DESCRIPTION 文件是
Package: testtruncnorm
Type: Package
Title: What the Package Does Using Title Case
Version: 1.0
Date: 2018-10-23
Author: Your Name
Maintainer: Your Name <your@email.com>
Description: More details about what the package does. See
<http://cran.r-project.org/doc/manuals/r-release/R-exts.html#The-
DESCRIPTION-file>
for details on how to write this part.
License: GPL (>= 2)
Imports: Rcpp (>= 0.12.19), RcppTN
LinkingTo: Rcpp, RcppArmadillo, RcppTN
我正在使用 RStudio create "R Package with RcppArmadillo" 开始。 RStudio 版本 1.1.456。 R 版本 3.5.1。 Windows10.
您必须确保 RcppTN
已附加。您可以使用
importFrom(RcppTN, rtn)
在 NAMESPACE
中。在 RcppTN
的文档中说应该添加
Depends: RcppTN
应该是一样的效果