简体   繁体   English

使用RStudio在R包中编译Rcpp代码时出错

[英]Error when compiling Rcpp code in an R package using RStudio

I am using Rstudio to create a package, and exploring the use of the Rcpp package to gain access to C++ code, however, when trying to build the package, and error is being thrown as follows: 我正在使用Rstudio创建一个包,并探索使用Rcpp包来获取对C ++代码的访问,但是,当尝试构建包时,错误被抛出如下:

fatal error: Rcpp.h: No such file or directory

Inline C++ code compiles fine, its only when considering standalone C++ files in the src folder, obviously referring to the #include <Rcpp.h> directive at the head of the .cpp file. 内联C ++代码编译很好,它只在考虑src文件夹中的独立C ++文件时,显然是指.cpp文件头部的#include <Rcpp.h>指令。

I think it may have something to do with environment variables, does anyone know what the correct configuration is and how to fix for Rstudio operating in an Ubuntu 12.04 LTS environment? 我认为它可能与环境变量有关,有谁知道正确的配置是什么以及如何修复在Ubuntu 12.04 LTS环境中运行的Rstudio?

The commands sourceCpp('./src/xyz.cpp') execute as to be expected, the error is being thrown when Build and Reload is executed from within the RStudio IDE. 命令sourceCpp('./src/xyz.cpp')按预期执行,当从RStudio IDE中执行Build and Reload时,抛出错误。

It is hard to say without having the package available. 如果没有可用的包装,很难说。 I guess you miss: 我想你错过了:

LinkingTo: Rcpp

in your DESCRIPTION file. 在您的描述文件中。

Did you by chance start with 'Create a package' in RStudio? 您是否偶然开始使用RStudio中的“创建包” If so, are you aware that you may have missed its sibbling option 'Create a package w/ Rcpp' ? 如果是这样,你是否意识到你可能已经错过了它的sibbling选项'用 Rcpp 创建一个包'

See the page on Using Rcpp with RStudio site for details, and particularly the final section on package building. 有关详细信息,请参阅有关使用Rcpp和RStudio站点的页面,特别是关于包构建的最后一节。

Also note that we wrote an entire vignette on using Rcpp with your own packages so I suggest you have a look at that too. 另请注意,我们写了一个关于在自己的包中使用Rcpp的整个插图所以我建议你也看一下。

I encountered this same symptom ( Rcpp.h: No such file or directory ) when trying to install the "xml2" package on an Ubuntu 14 system. 尝试在Ubuntu 14系统上安装“xml2”软件包时,我遇到了同样的症状( Rcpp.h: No such file or directory )。 In my case the root cause appeared to be a bad installation of package "Rcpp". 在我的情况下,根本原因似乎是包“Rcpp”的错误安装。 Some of the files were there (Rcpp/libs) but others were not (Rcpp/include). 有些文件在那里(Rcpp / libs),但其他文件没有(Rcpp / include)。 I am not sure how the system got into this state but I suspect an installation of that package terminated part way through. 我不确定系统是如何进入这种状态的,但我怀疑该软件包的安装已经部分终止。 Re-installing package "Rcpp" cleared up the issue for me. 重新安装包“Rcpp”为我解决了这个问题。

This is because your GCC has been updated, and it is different than the one you had when you installed R. I had the same problem. 这是因为您的GCC已更新,它与您安装R时的GCC不同。我遇到了同样的问题。

I removed the package "Rccp" by using: 我使用以下命令删除了包“Rccp”:

remove.packages("Rcpp")

Then you need to install it again. 然后你需要再次安装它。 Just run: 赶紧跑:

source("https://bioconductor.org/biocLite.R")
biocLite("Rcpp")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM