RcppTN .cpp 脚本在来源时有效,但在库中编译时无效

编程入门 行业动态 更新时间:2024-10-27 13:31:16
本文介绍了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> Description: More details about what the package does. See <cran.r-project/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 脚本在来源时有效,但在库中编译时无效

本文发布于:2023-11-13 21:36:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1585385.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:但在   脚本   库中   来源   RcppTN

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!