C ++函数不可用 [英] C++ function not available

查看:105
本文介绍了C ++函数不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下文件cumsum_bounded.cpp

I have the following file cumsum_bounded.cpp

#include <Rcpp.h>
using namespace Rcpp;

//' Cumulative sum.
//' @param x numeric vector
//' @param low lower bound
//' @param high upper bound
//' @param res bounded numeric vector
//' @export
//' @return bounded numeric vector
// [[Rcpp::export]]
NumericVector cumsum_bounded(NumericVector x, double low, double high) {
    NumericVector res(x.size());
    double acc = 0;
    for (int i=0; i < x.size(); ++i) {
        acc += x[i];
        if (acc < low)  acc = low;
        else if (acc > high)  acc = high;
        res[i] = acc;
    }
    return res;
}

然后我构建并修改重新加载并测试我的新函数。

I then Build & Reload and test out my new function.

cumsum_bounded(c(1, -2, 3), low = 2, high = 10)
[1] 1 0 3

然后我建立了文档。
devtools :: document()

Then I build the documentation. devtools::document()

当我 Build&重新加载一切都可以正常编译。

When I Build & Reload everything compiles fine.

但是当我运行 cumsum_bounded(c(1,2,3),low = 2,高= 10)我收到错误:

But when I run cumsum_bounded(c(1, 2, 3), low= 2, high = 10) I get the error:

Error in .Call("joshr_cumsum_bounded", PACKAGE = "joshr", x, low, high) : 
  "joshr_cumsum_bounded" not available for .Call() for package "joshr"

名称空间

# Generated by roxygen2: do not edit by hand

export(cumsum_bounded)

更新:

如果我如上所述创建一个新项目,并且不要使用 Build&重新加载函数,而不是devtools :: loadall(),它将起作用。但是一旦我按 Build&重新加载按钮,它会向侧面倾斜。

If I create a new project as above and DON'T use the Build & Reload function but rather devtools::loadall(), it will work. But once I press that Build & Reload button, it goes sideways.

推荐答案

您可能需要此行

useDynLib(<pkg>) ## substitute your package name for <pkg>

。如果您使用的是roxygen2,则可以添加一行,例如#'@useDynLib< pkg> 在文档中的某个位置,将包名替换为< pkg>

in your NAMESPACE file. If you're using roxygen2, you can add a line e.g. #' @useDynLib <pkg> somewhere in your documentation, substituting your package name for <pkg> as appropriate.

编辑:并且为了响应您的其他错误消息,您可能需要从Rcpp导入某些内容,例如添加行 @importFrom Rcpp evalCpp

And in response to your other error message, you likely need to import something from Rcpp, e.g. add the line @importFrom Rcpp evalCpp.

这篇关于C ++函数不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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