RcppTN .cpp 脚本在来源时有效,但在库中编译时无效 [英] RcppTN .cpp script works when sourced but not when compiled in library

查看:44
本文介绍了RcppTN .cpp 脚本在来源时有效,但在库中编译时无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个 R 包,该包使用 .cpp 脚本中截断法线的随机抽取.我正在使用 pckage RcppTN 中的 rtn1 函数.如果我提供代码,则该功能可以正常工作.构建包后,我收到错误:

I am trying to create a R package that uses random draws from a truncated normal in a .cpp script. I am using the rtn1 function from the pckage RcppTN. If I source the code, the function works fine. Once I build the package I get the error:

> library(testtruncnorm)
> testtruncnorm()
Error in testtruncnorm::testtruncnorm() :
  function 'RcppTN_rtn1' not provided by package 'RcppTN'

简化的 .cpp 代码在这里

Simplified .cpp code is here

#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; 
 }

我的 NAMESPACE 文件是

My NAMESPACE file is

useDynLib(testtruncnorm, .registration=TRUE)
importFrom(Rcpp, evalCpp)
exportPattern("^[[:alpha:]]+")

我的描述文件是

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 创建R Package with RcppArmadillo"来开始.RStudio 版本 1.1.456.R 版本 3.5.1.视窗 10.

I am using RStudio create "R Package with RcppArmadillo" to get started. RStudio version 1.1.456. R version 3.5.1. Windows 10.

推荐答案

您必须确保 RcppTN 已附加.您可以使用

You have to make sure that RcppTN gets attached. You can do this using

importFrom(RcppTN, rtn)

NAMESPACE 中.在 RcppTN 的文档中,它说应该添加

in NAMESPACE. In the documentation for RcppTN it says that one should add

Depends: RcppTN

应该有同样的效果.

这篇关于RcppTN .cpp 脚本在来源时有效,但在库中编译时无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆