Rcpp:为什么我不能在我定义的包中运行该函数? [英] Rcpp: why I can not run the function in my defined package?

查看:50
本文介绍了Rcpp:为什么我不能在我定义的包中运行该函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下步骤来实现我自己的包:

I use the following steps to achieve my own package:

1)我试着写一个非常简单的函数如下:

1)I try to write a very simple function as follows:

#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::export]]
int foo() {
return 6;
}

2) 我用骨架把它做成一个包:

2) I use skeleton to make it into a package:

Rcpp.package.skeleton("newpackage",example_code=FALSE,cpp_files=c("New.cpp"))

3) 我用命令运行 cpp:

3) I run cpp with command:

source("~/newpackage/src/New.cpp")

4) 运行 compileAttributes 来加载包:

4) run compileAttributes to load the package:

 compileAttributes(pkgdir="/home/tw72/newpackage",verbose = getOption("verbose"))

在此之后我想在 R 中调用该函数:

After this I want to call the function in R:

foo <- function( )
{
.Call("foo",PACKAGE="newpackage")
}

那么错误是:

Error in .Call("foo", PACKAGE = "newpackage") :

foo"不适用于包newpackage"的 .Call()

"foo" not available for .Call() for package "newpackage"

我遇到了同样的问题,但我还是不能弄清楚会发生什么.你可以帮帮我吗?我上面的步骤有什么问题?谢谢.

I met the same problem, but I still can not figure out what happens. Could you help me? What's wrong with my above steps? Thanks.

推荐答案

在我的脑海中,它看起来很完整,但请尝试

From the top of my head, it looks pretty complete but do try

R> Rcpp.package.skeleton("newpackage",
+                        example_code=FALSE,      ## useful but not required
+                        cpp_files=c("New.cpp"),  ## may not be required 
+                        attributes=TRUE)         ## this is important
R>

因为Rcpp modulesRcpp attributes 都需要开启.

as both Rcpp modules and Rcpp attributes need to be turned on.

之后,事情应该像你做所需的compileAttributes一样工作.

After that, things should work as you do the required compileAttributes.

它更简单.只需执行我上面概述的 Rcpp.package.skeleton() 调用,即添加 attributes=TRUE 之后你就完成了-- 安装包并测试.

It is even simpler. Just do do the Rcpp.package.skeleton() call I outlined above, that is with the added attributes=TRUE after which you are done -- install the package and test it.

这篇关于Rcpp:为什么我不能在我定义的包中运行该函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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