我试图在我的 R 包开发目录中运行一个简单的测试 C++ 文件,其中 Rcpp 位于说目录 "my_R_package_dir/src/my_file_location.cpp"
:
#include <Rcpp.h>
// [[Rcpp::export]]
int plusone() {
return 1 + 1;
}
但是当运行 Rcpp::sourceCpp("src/my_file_location.cpp")
时,R 控制台会给出以下警告:
Warning message:
In normalizePath(path.expand(path), winslash, mustWork) :
path[1]="C:/Users/myself/my_R_package_dir/src/../inst/include": file not found
导出的函数 plusone()
确实有效,但我可以清楚地看到它出于某种原因试图访问我拥有的“inst”目录中名为“include”的不存在的文件。我猜它想访问 Rcpp.h 文件,但我可能需要以某种方式指示它指向的路径?我该怎么做?
附言这也会导致包构建失败,部分消息还表明没有这样的文件或目录 Rcpp.h
.
我想我需要一个 Makevars.win
和 Makevars
文件,我把它们都放入 src
中,它们看起来像这样:
PKG_CPPFLAGS=`Rscript -e 'Rcpp:::CxxFlags()'`
PKG_LIBS=`Rscript -e 'Rcpp:::LdFlags()'`
CC=C:\msys64\mingw64\bin\g++.exe
CXX=C:\msys64\mingw64\bin\gcc.exe
但无济于事。我在装有 Rtools 4.3、gcc 和 g++ 的 Windows 设备上。