Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/153.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用RcppEigen 我是C++初学者,我想在C++代码中添加一个新的包“CRTCPCPEGEGEN”到RCPPEGIGN,而在运行一些 BAT < /C>文件时,有些事情出错了。任何帮助都将不胜感激 这是一个C++代码函数,名为“CRTCPCPIGEN”,我想在文件“Src”中添加到RcppEigen: #include < Rcpp.h > #include < RcppEigen.h > #include <Eigen/Dense> #include <iostream> #include <string> using Eigen::MatrixXd; using namespace std; using namespace Rcpp; using namespace RcppEigen; using namespace Eigen; RcppExport SEXP MatOp(SEXP Xr, SEXP Yr, SEXP Kr) { MatrixXd X = RcppEigen::as<MatrixXd>(Xr); MatrixXd Y = RcppEigen::as<MatrixXd>(Yr); string K = Rcpp::as<string>(Kr); int n=X.rows(); int p=X.cols(); int nY=Y.cols(); MatrixXd I(n,n); I.setIdentity(n,n); double SSE=(Y.transpose()*(I-X*(X.transpose()*X).inverse()*X.transpose())*Y).determinant(); if(Criteria=="k1") return (wrap(n*log(SSE/n)+log(n)*p)); if(Criteria=="k2") return (wrap(n*log(SSE/n)+(2*p*nY*n+nY*(nY+1))/n-2/n+n+2)); }_C++_Windows_R_Eigen_Rcpp - Fatal编程技术网

如何使用RcppEigen 我是C++初学者,我想在C++代码中添加一个新的包“CRTCPCPEGEGEN”到RCPPEGIGN,而在运行一些 BAT < /C>文件时,有些事情出错了。任何帮助都将不胜感激 这是一个C++代码函数,名为“CRTCPCPIGEN”,我想在文件“Src”中添加到RcppEigen: #include < Rcpp.h > #include < RcppEigen.h > #include <Eigen/Dense> #include <iostream> #include <string> using Eigen::MatrixXd; using namespace std; using namespace Rcpp; using namespace RcppEigen; using namespace Eigen; RcppExport SEXP MatOp(SEXP Xr, SEXP Yr, SEXP Kr) { MatrixXd X = RcppEigen::as<MatrixXd>(Xr); MatrixXd Y = RcppEigen::as<MatrixXd>(Yr); string K = Rcpp::as<string>(Kr); int n=X.rows(); int p=X.cols(); int nY=Y.cols(); MatrixXd I(n,n); I.setIdentity(n,n); double SSE=(Y.transpose()*(I-X*(X.transpose()*X).inverse()*X.transpose())*Y).determinant(); if(Criteria=="k1") return (wrap(n*log(SSE/n)+log(n)*p)); if(Criteria=="k2") return (wrap(n*log(SSE/n)+(2*p*nY*n+nY*(nY+1))/n-2/n+n+2)); }

如何使用RcppEigen 我是C++初学者,我想在C++代码中添加一个新的包“CRTCPCPEGEGEN”到RCPPEGIGN,而在运行一些 BAT < /C>文件时,有些事情出错了。任何帮助都将不胜感激 这是一个C++代码函数,名为“CRTCPCPIGEN”,我想在文件“Src”中添加到RcppEigen: #include < Rcpp.h > #include < RcppEigen.h > #include <Eigen/Dense> #include <iostream> #include <string> using Eigen::MatrixXd; using namespace std; using namespace Rcpp; using namespace RcppEigen; using namespace Eigen; RcppExport SEXP MatOp(SEXP Xr, SEXP Yr, SEXP Kr) { MatrixXd X = RcppEigen::as<MatrixXd>(Xr); MatrixXd Y = RcppEigen::as<MatrixXd>(Yr); string K = Rcpp::as<string>(Kr); int n=X.rows(); int p=X.cols(); int nY=Y.cols(); MatrixXd I(n,n); I.setIdentity(n,n); double SSE=(Y.transpose()*(I-X*(X.transpose()*X).inverse()*X.transpose())*Y).determinant(); if(Criteria=="k1") return (wrap(n*log(SSE/n)+log(n)*p)); if(Criteria=="k2") return (wrap(n*log(SSE/n)+(2*p*nY*n+nY*(nY+1))/n-2/n+n+2)); },c++,windows,r,eigen,rcpp,C++,Windows,R,Eigen,Rcpp,build crtrcppegen包Linux源代码.bat文件是: Rcmd INSTALL --build CRTRCppEigen PAUSE Rcmd build CRTRCppEigen pause Rcmd INSTALL CRTRCppEigen PAUSE Rcmd check CRTRCppEigen PAUSE 安装crtrcppegen包.bat文件是: Rcmd INSTALL --build CRTRCppEigen PAUSE Rcmd build

build crtrcppegen包Linux源代码.bat
文件是:

Rcmd INSTALL --build CRTRCppEigen

PAUSE
Rcmd build CRTRCppEigen

pause
Rcmd INSTALL CRTRCppEigen

PAUSE
Rcmd check CRTRCppEigen

PAUSE
安装crtrcppegen包.bat
文件是:

Rcmd INSTALL --build CRTRCppEigen

PAUSE
Rcmd build CRTRCppEigen

pause
Rcmd INSTALL CRTRCppEigen

PAUSE
Rcmd check CRTRCppEigen

PAUSE
检查crtrcppegen package.bat
文件为:

Rcmd INSTALL --build CRTRCppEigen

PAUSE
Rcmd build CRTRCppEigen

pause
Rcmd INSTALL CRTRCppEigen

PAUSE
Rcmd check CRTRCppEigen

PAUSE
环境变量是

C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;c:\Program Files (x86)\Hewlett-Packard\HP ProtectTools Security Manager\Bin\;c:\Program Files\Intel\DMIX;C:\Program Files (x86)\Intel\Services\IPT\;C:\Program Files\SASHome\Secure;C:\Program Files\SASHome\x86\Secure;C:\Opt\MiKTeX2.9\miktex\bin\x64\;C:\Opt\MiKTeX2.9\miktex\bin\x64\;C:\Rtools\bin;C:\Rtools\gcc-4.6.3\bin;C:\R\R-3.1.1\bin\x64;C:\R\R-3.1.1\bin\i386;
当我运行
build crtrcppeheng包Windows Binary.bat
时,出现错误:

    * installing *source* package 'CRTRCppEigen' ...
    ** libs

    *** arch - i386
    cygwin warning:
      MS-DOS style path detected: C:/R/R-31~1.1/etc/i386/Makeconf
      Preferred POSIX equivalent is: /cygdrive/c/R/R-31~1.1/etc/i386/Makeconf
      CYGWIN environment variable option "nodosfilewarning" turns off this warning.
      Consult the user's guide for more details about POSIX paths:
        http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
    g++ -m32 -I"C:/R/R-31~1.1/include" -DNDEBUG    -I"C:/Users/LJH/Documents/R/win-library/3.1/Rcpp/include" -I"C:/Users/LJH/Documents/R/win-library/3.1/RcppEigen/include" -I"d:/RCompile/CRANpkg/extralibs64/local/include"     -O2 -Wall  -mtune=core2 -c CRTRCppEigen.cpp -o CRTRCppEigen.o
    CRTRCppEigen.cpp:3:20: fatal error:  Rcpp.h : No such file or directory
    compilation terminated.
    make: *** [CRTRCppEigen.o] Error 1
    Warning: running command 'make -f "Makevars.win" -f "C:/R/R-31~1.1/etc/i386/Makeconf" -f "C:/R/R-31~1.1/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="CRTRCppEigen.dll" OBJECTS="CRTRCppEigen.o RcppExports.o rcppeigen_hello_world.o"' had status 2
    cygwin warning:
      MS-DOS style path detected: C:/R/R-31~1.1/etc/i386/Makeconf
      Preferred POSIX equivalent is: /cygdrive/c/R/R-31~1.1/etc/i386/Makeconf
      CYGWIN environment variable option "nodosfilewarning" turns off this warning.
      Consult the user's guide for more details about POSIX paths:
        http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
    g++ -m32 -I"C:/R/R-31~1.1/include" -DNDEBUG    -I"C:/Users/LJH/Documents/R/win-library/3.1/Rcpp/include" -I"C:/Users/LJH/Documents/R/win-library/3.1/RcppEigen/include" -I"d:/RCompile/CRANpkg/extralibs64/local/include"     -O2 -Wall  -mtune=core2 -c CRTRCppEigen.cpp -o CRTRCppEigen.o
    CRTRCppEigen.cpp:3:20: fatal error:  Rcpp.h : No such file or directory
    compilation terminated.
    make: *** [CRTRCppEigen.o] Error 1
    Warning: running command 'make -f "Makevars.win" -f "C:/R/R-31~1.1/etc/i386/Makeconf" -f "C:/R/R-31~1.1/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="CRTRCppEigen.dll" OBJECTS="CRTRCppEigen.o RcppExports.o rcppeigen_hello_world.o" symbols.rds' had status 2
    ERROR: compilation failed for package 'CRTRCppEigen'
    * removing 'C:/Users/LJH/Documents/CRTRCppEigen.Rcheck/CRTRCppEigen'
但在这种情况下,Rcpp包是有效的。所以我猜C++代码有问题。

你的错误是

crtrcppegen.cpp:3:20:致命错误:Rcpp.h:没有这样的文件或目录

这不应该发生,因为您在
说明
中似乎有
链接到:Rcpp

要检查,我只是在Windows框上执行了以下操作:

R> setwd("c:/temp")
R> RcppEigen.package.skeleton(name="quicktest")
Creating directories ...
Creating DESCRIPTION ...
Creating NAMESPACE ...
Creating Read-and-delete-me ...
Saving functions and data ...
Making help files ...
Done.
Further steps are described in './quicktest/Read-and-delete-me'.

Adding RcppEigen settings
 >> added Imports: Rcpp, RcppEigen
 >> added LinkingTo: Rcpp, RcppEigen
 >> added useDynLib directive to NAMESPACE
 >> added Makevars file
 >> added Makevars.win file
 >> added example src file using Eigen classes
 >> invoked Rcpp::compileAttributes to create wrappers
R> 
然后是直接安装:

R> install.packages("quicktest", repos=NULL, type="source")
Installing package into ‘c:/opt/R-library’
(as ‘lib’ is unspecified)
* installing *source* package 'quicktest' ...
** libs

*** arch - i386
g++ -m32 -I"C:/opt/R-CURR~1/include" -DNDEBUG    -I"c:/opt/R-library/Rcpp/include" -I"c:/opt/R-library/RcppEigen/include" -I"d:/RCompile/CRANpkg/extralibs64/local/include"     -O2 -Wall  -mtune=core2 -c RcppExports.cpp -o RcppExports.o
g++ -m32 -I"C:/opt/R-CURR~1/include" -DNDEBUG    -I"c:/opt/R-library/Rcpp/include" -I"c:/opt/R-library/RcppEigen/include" -I"d:/RCompile/CRANpkg/extralibs64/local/include"     -O2 -Wall  -mtune=core2 -c rcppeigen_hello_world.cpp -o rcppeigen_hello_world.o
g++ -m32 -shared -s -static-libgcc -o quicktest.dll tmp.def RcppExports.o rcppeigen_hello_world.o -Ld:/RCompile/CRANpkg/extralibs64/local/lib/i386 -Ld:/RCompile/CRANpkg/extralibs64/local/lib -LC:/opt/R-CURR~1/bin/i386 -lR
installing to c:/opt/R-library/quicktest/libs/i386

*** arch - x64
g++ -m64 -I"C:/opt/R-CURR~1/include" -DNDEBUG    -I"c:/opt/R-library/Rcpp/include" -I"c:/opt/R-library/RcppEigen/include" -I"d:/RCompile/CRANpkg/extralibs64/local/include"     -O2 -Wall  -mtune=core2 -c RcppExports.cpp -o RcppExports.o
g++ -m64 -I"C:/opt/R-CURR~1/include" -DNDEBUG    -I"c:/opt/R-library/Rcpp/include" -I"c:/opt/R-library/RcppEigen/include" -I"d:/RCompile/CRANpkg/extralibs64/local/include"     -O2 -Wall  -mtune=core2 -c rcppeigen_hello_world.cpp -o rcppeigen_hello_world.o
g++ -m64 -shared -s -static-libgcc -o quicktest.dll tmp.def RcppExports.o rcppeigen_hello_world.o -Ld:/RCompile/CRANpkg/extralibs64/local/lib/x64 -Ld:/RCompile/CRANpkg/extralibs64/local/lib -LC:/opt/R-CURR~1/bin/x64 -lR
installing to c:/opt/R-library/quicktest/libs/x64
** R
** preparing package for lazy loading
** help
Warning: c:/TEMP/quicktest/man/quicktest-package.Rd:32: All text must be in a section
Warning: c:/TEMP/quicktest/man/quicktest-package.Rd:33: All text must be in a section
*** installing help indices
** building package indices
** testing if installed package can be loaded
*** arch - i386
*** arch - x64
* DONE (quicktest)
R> 
正如您所看到的,它可以按预期工作,因此我建议您将空骨架包与您的进行比较


FWIW我也“通常”在命令行上工作,所以你在那里做的看起来也不错。这就是说,你的R
路径
条目在末尾,手册强烈建议将它们放在前面。

我想这些额外的空格需要去掉(
#include
->
#include
)哦,好的,凯文!是的,它确实有效。谢谢大家。