无法更新 R 包文档:`系统命令 'R' 失败`(#using 语句不起作用)
can't update R package documentation: `System command 'R' failed` (#using statements don't work)
我有一个 RcppEigen project 正在尝试更新文档。该项目仅将一个 c++ 函数导出到 R。
不幸的是,当我 运行 devtools::document(pkg = "~/pfexamplesinr/")
或 roxygen2::roxygenize(roclets="rd", package.dir = "pfexamplesinr/")
时遇到问题,错误消息如下。
它说了一些关于 System command 'R' failed
的事情。整个构建输出太大而无法粘贴(我超过了字符限制)。如果我搜索第一个错误,它是 RcppExports.cpp:15:21: error: ‘Map’ was not declared in this scope
。关于 #include
指令和 // [[Rcpp::depends(RcppEigen)]]
语句的顺序有什么有趣的事情吗?
注意:当我使用 Rcpp::sourceCpp('pfexamplesinr/src/likelihoods.cpp')
时代码构建良好
编辑:当我删除 #using
语句并在必要时添加 Eigen::
时,这个问题就消失了。
#include <RcppEigen.h>
#include "svol_sisr_hilb.h"
#include "resamplers.h"
// [[Rcpp::depends(RcppEigen)]]
// choose number of particles, and number of bits for inverse Hilbert curve map
#define NP 500
#define NB 5
#define debug_mode false
using Eigen::Map;
using Eigen::MatrixXd;
using Eigen::VectorXd;
using hilb_sys_resamp_T = pf::resamplers::sys_hilb_resampler<NP,1,NB,double>;
using svol_pfilter = svol_sisr_hilb<NP,NB, hilb_sys_resamp_T, double, debug_mode>;
// helpful notes:
// 1.
// parameters passed to svol_pfilter() ctor are in the following order: phi, beta, sigma
// 2.
// uProposal will be dimension (time X (particles + 1))
// first NP columns will be used for state sampling
// last column will be used for resampling at each time point
// 3.
// choosing NP or NB too large will result in Whosebug
// number of particles is set in two places: in the #define directive and also used in your R script
// [[Rcpp::export]]
double svolApproxLL(const Map<VectorXd> y, const Map<VectorXd> thetaProposal, const Map<MatrixXd> uProposal) {
// construct particle filter object
svol_pfilter pf(thetaProposal(0), thetaProposal(1), thetaProposal(2)); // order: phi, beta, sigma
// iterate over the data
double log_like(0.0);
Eigen::Matrix<double,1,1> yt;
std::array<Eigen::Matrix<double,1,1>, NP> uStateTransition;
Eigen::Matrix<double,1,1> uResample;
for(int time = 0; time < y.rows(); ++time){
// change types of inputs
yt(0) = y(time);
for(unsigned particle = 0; particle < NP; ++particle) {
uStateTransition[particle] = uProposal.block(time,particle,1,1);
}
uResample(0) = uProposal(time,NP);
// std::cout << yt.transpose() << "\n";
// for(unsigned int i = 0; i < NP; ++i)
// std::cout << uStateTransition[i] << ", ";
// std::cout << "\n----------\n";
// update particle filter and log-likelihood
pf.filter(yt, uStateTransition, uResample);
log_like += pf.getLogCondLike();
}
//return es.eigenvalues();
return log_like;
}
// You can include R code blocks in C++ files processed with sourceCpp
// (useful for testing and development). The R code will be automatically
// run after the compilation.
/*** R
numTime <- 3
numParts <- 500 # make sure this agrees with NP
u <- matrix(rnorm(numTime*(numParts+1)), ncol = numParts+1)
params <- c(.9, 1, .1) # -1 < phi < 1, beta, sigma > 0
hist(replicate(100, svolApproxLL(rnorm(numTime), params, u)))
*/
Error in (function (command = NULL, args = character(), error_on_status = TRUE, :
System command 'R' failed, exit status: 1, stdout + stderr (last 10 lines):
E> /home/taylor/R/x86_64-pc-linux-gnu-library/4.1/RcppEigen/include/Eigen/src/Core/MatrixBase.h:48:34: required from ‘class Eigen::MatrixBase<Eigen::Matrix<double, -1, 1> >’
E> /home/taylor/R/x86_64-pc-linux-gnu-library/4.1/RcppEigen/include/Eigen/src/Core/PlainObjectBase.h:98:7: required from ‘class Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1> >’
E> /home/taylor/R/x86_64-pc-linux-gnu-library/4.1/RcppEigen/include/Eigen/src/Core/Matrix.h:178:7: required from ‘class Eigen::Matrix<double, -1, 1>’
E> /home/taylor/R/x86_64-pc-linux-gnu-library/4.1/Rcpp/include/Rcpp/InputParameter.h:77:11: required from ‘class Rcpp::ConstReferenceInputParameter<Eigen::Matrix<double, -1, 1> >’
E> RcppExports.cpp:43:74: required from here
E> /home/taylor/R/x86_64-pc-linux-gnu-library/4.1/RcppEigen/include/Eigen/src/Core/DenseCoeffsBase.h:5
感谢您提供 URL 给重现者。这个错误,因为它经常发生,似乎是 'hidden' 更深的 devtools::document()
。
当我使用 'current everything' 从 CRAN 运行 Ubuntu 21.04 将您的存储库克隆到一台机器上并执行我通常的两步
compAttr.r # shell wrapper for Rcpp::compileAttributes
roxy.r -f # shell wrapper for roxygenize()
(使用我的小包中的这些帮助脚本),
我泪流满面,因为你的代码使用了 C++17 语句,却没有指定 C++17 作为编译标准。
换句话说,你这边的普通错误,独立于 Rcpp 或其他工具。
edd@rob:~/git/Whosebug/68985867/pfexamplesinr(master)$ compAttr.r
edd@rob:~/git/Whosebug/68985867/pfexamplesinr(master)$ roxy.r -f
ℹ Loading pfexamplesinr
Exports from /home/edd/git/Whosebug/68985867/pfexamplesinr/src/likelihoods.cpp:
double svolApproxLL(Eigen::Map<Eigen::VectorXd> y, Eigen::Map<Eigen::VectorXd> thetaProposal, Eigen::Map<Eigen::MatrixXd> uProposal)
Exports from /home/edd/git/Whosebug/68985867/pfexamplesinr/src/rcppeigen_hello_world.cpp:
Eigen::MatrixXd rcppeigen_hello_world()
Eigen::MatrixXd rcppeigen_outerproduct(const Eigen::VectorXd& x)
double rcppeigen_innerproduct(const Eigen::VectorXd& x)
Rcpp::List rcppeigen_bothproducts(const Eigen::VectorXd& x)
Exports from /home/edd/git/Whosebug/68985867/pfexamplesinr/src/resamplers.h:
Exports from /home/edd/git/Whosebug/68985867/pfexamplesinr/src/rv_eval.h:
Exports from /home/edd/git/Whosebug/68985867/pfexamplesinr/src/rv_samp.h:
/home/edd/git/Whosebug/68985867/pfexamplesinr/src/RcppExports.cpp updated.
/home/edd/git/Whosebug/68985867/pfexamplesinr/R/RcppExports.R updated.
Re-compiling pfexamplesinr
─ installing *source* package ‘pfexamplesinr’ ...
** using staged installation
** using staged installation
** libs
ccache g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppEigen/include' -fpic -g -O3 -Wall -pipe -pedantic -Wno-misleading-indentation -Wno-unused -Wno-ignored-attributes -Wno-class-memaccess -c RcppExports.cpp -o RcppExports.o
ccache g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppEigen/include' -fpic -g -O3 -Wall -pipe -pedantic -Wno-misleading-indentation -Wno-unused -Wno-ignored-attributes -Wno-class-memaccess -c likelihoods.cpp -o likelihoods.o
In file included from svol_sisr_hilb.h:8,
from likelihoods.cpp:1:
sisr_filter.h: In member function ‘void pf::filters::SISRFilter<nparts, dimx, dimy, resamp_t, float_t, debug>::filter(const osv&, const std::vector<std::function<const Eigen::Matrix<float_t, -1, -1>(const Eigen::Matrix<float_t, dimx, 1>&)> >&)’:
sisr_filter.h:229:16: warning: ‘if constexpr’ only available with ‘-std=c++17’ or ‘-std=gnu++17’
229 | if constexpr(debug)
| ^~~~~~~~~
sisr_filter.h:262:16: warning: ‘if constexpr’ only available with ‘-std=c++17’ or ‘-std=gnu++17’
262 | if constexpr(debug)
| ^~~~~~~~~
sisr_filter.h:288:16: warning: ‘if constexpr’ only available with ‘-std=c++17’ or ‘-std=gnu++17’
288 | if constexpr(debug)
| ^~~~~~~~~
sisr_filter.h:320:16: warning: ‘if constexpr’ only available with ‘-std=c++17’ or ‘-std=gnu++17’
320 | if constexpr(debug)
| ^~~~~~~~~
sisr_filter.h: In member function ‘void pf::filters::SISRFilterCRN<nparts, dimx, dimy, dimu, dimur, resamp_t, float_t, debug>::filter(const osv&, const arrayUs&, const usvr&, const std::vector<std::function<const Eigen::Matrix<float_t, -1, -1>(const Eigen::Matrix<float_t, dimx, 1>&)> >&)’:
sisr_filter.h:559:16: warning: ‘if constexpr’ only available with ‘-std=c++17’ or ‘-std=gnu++17’
559 | if constexpr(debug)
| ^~~~~~~~~
sisr_filter.h:592:16: warning: ‘if constexpr’ only available with ‘-std=c++17’ or ‘-std=gnu++17’
592 | if constexpr(debug)
| ^~~~~~~~~
sisr_filter.h:618:16: warning: ‘if constexpr’ only available with ‘-std=c++17’ or ‘-std=gnu++17’
618 | if constexpr(debug)
| ^~~~~~~~~
sisr_filter.h:650:16: warning: ‘if constexpr’ only available with ‘-std=c++17’ or ‘-std=gnu++17’
650 | if constexpr(debug)
| ^~~~~~~~~
In file included from likelihoods.cpp:2:
resamplers.h: In member function ‘void pf::resamplers::sys_hilb_resampler<nparts, dimx, num_hilb_bits, float_t>::resampLogWts(pf::resamplers::sys_hilb_resampler<nparts, dimx, num_hilb_bits, float_t>::arrayVec&, pf::resamplers::sys_hilb_resampler<nparts, dimx, num_hilb_bits, float_t>::arrayFloat&, const usvr&) [with long unsigned int nparts = 500; long unsigned int dimx = 1; long unsigned int num_hilb_bits = 5; float_t = double]’:
resamplers.h:1089:36: warning: ‘idx’ may be used uninitialized in this function [-Wmaybe-uninitialized]
1089 | tmpPartics[i] = sortedParts[idx];
| ~~~~~~~~~~~^
ccache g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppEigen/include' -fpic -g -O3 -Wall -pipe -pedantic -Wno-misleading-indentation -Wno-unused -Wno-ignored-attributes -Wno-class-memaccess -c rcppeigen_hello_world.cpp -o rcppeigen_hello_world.o
ccache g++ -std=gnu++14 -Wl,-S -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -flto=auto -Wl,-z,relro -o pfexamplesinr.so RcppExports.o likelihoods.o rcppeigen_hello_world.o -L/usr/lib/R/lib -lR
installing to /tmp/devtools_install_2dc74d5a52ad61/00LOCK-pfexamplesinr/00new/pfexamplesinr/libs
** checking absolute paths in shared objects and dynamic libraries
─ DONE (pfexamplesinr)
edd@rob:~/git/Whosebug/68985867/pfexamplesinr(master)$
我有一个 RcppEigen project 正在尝试更新文档。该项目仅将一个 c++ 函数导出到 R。
不幸的是,当我 运行 devtools::document(pkg = "~/pfexamplesinr/")
或 roxygen2::roxygenize(roclets="rd", package.dir = "pfexamplesinr/")
时遇到问题,错误消息如下。
它说了一些关于 System command 'R' failed
的事情。整个构建输出太大而无法粘贴(我超过了字符限制)。如果我搜索第一个错误,它是 RcppExports.cpp:15:21: error: ‘Map’ was not declared in this scope
。关于 #include
指令和 // [[Rcpp::depends(RcppEigen)]]
语句的顺序有什么有趣的事情吗?
注意:当我使用 Rcpp::sourceCpp('pfexamplesinr/src/likelihoods.cpp')
编辑:当我删除 #using
语句并在必要时添加 Eigen::
时,这个问题就消失了。
#include <RcppEigen.h>
#include "svol_sisr_hilb.h"
#include "resamplers.h"
// [[Rcpp::depends(RcppEigen)]]
// choose number of particles, and number of bits for inverse Hilbert curve map
#define NP 500
#define NB 5
#define debug_mode false
using Eigen::Map;
using Eigen::MatrixXd;
using Eigen::VectorXd;
using hilb_sys_resamp_T = pf::resamplers::sys_hilb_resampler<NP,1,NB,double>;
using svol_pfilter = svol_sisr_hilb<NP,NB, hilb_sys_resamp_T, double, debug_mode>;
// helpful notes:
// 1.
// parameters passed to svol_pfilter() ctor are in the following order: phi, beta, sigma
// 2.
// uProposal will be dimension (time X (particles + 1))
// first NP columns will be used for state sampling
// last column will be used for resampling at each time point
// 3.
// choosing NP or NB too large will result in Whosebug
// number of particles is set in two places: in the #define directive and also used in your R script
// [[Rcpp::export]]
double svolApproxLL(const Map<VectorXd> y, const Map<VectorXd> thetaProposal, const Map<MatrixXd> uProposal) {
// construct particle filter object
svol_pfilter pf(thetaProposal(0), thetaProposal(1), thetaProposal(2)); // order: phi, beta, sigma
// iterate over the data
double log_like(0.0);
Eigen::Matrix<double,1,1> yt;
std::array<Eigen::Matrix<double,1,1>, NP> uStateTransition;
Eigen::Matrix<double,1,1> uResample;
for(int time = 0; time < y.rows(); ++time){
// change types of inputs
yt(0) = y(time);
for(unsigned particle = 0; particle < NP; ++particle) {
uStateTransition[particle] = uProposal.block(time,particle,1,1);
}
uResample(0) = uProposal(time,NP);
// std::cout << yt.transpose() << "\n";
// for(unsigned int i = 0; i < NP; ++i)
// std::cout << uStateTransition[i] << ", ";
// std::cout << "\n----------\n";
// update particle filter and log-likelihood
pf.filter(yt, uStateTransition, uResample);
log_like += pf.getLogCondLike();
}
//return es.eigenvalues();
return log_like;
}
// You can include R code blocks in C++ files processed with sourceCpp
// (useful for testing and development). The R code will be automatically
// run after the compilation.
/*** R
numTime <- 3
numParts <- 500 # make sure this agrees with NP
u <- matrix(rnorm(numTime*(numParts+1)), ncol = numParts+1)
params <- c(.9, 1, .1) # -1 < phi < 1, beta, sigma > 0
hist(replicate(100, svolApproxLL(rnorm(numTime), params, u)))
*/
Error in (function (command = NULL, args = character(), error_on_status = TRUE, :
System command 'R' failed, exit status: 1, stdout + stderr (last 10 lines):
E> /home/taylor/R/x86_64-pc-linux-gnu-library/4.1/RcppEigen/include/Eigen/src/Core/MatrixBase.h:48:34: required from ‘class Eigen::MatrixBase<Eigen::Matrix<double, -1, 1> >’
E> /home/taylor/R/x86_64-pc-linux-gnu-library/4.1/RcppEigen/include/Eigen/src/Core/PlainObjectBase.h:98:7: required from ‘class Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1> >’
E> /home/taylor/R/x86_64-pc-linux-gnu-library/4.1/RcppEigen/include/Eigen/src/Core/Matrix.h:178:7: required from ‘class Eigen::Matrix<double, -1, 1>’
E> /home/taylor/R/x86_64-pc-linux-gnu-library/4.1/Rcpp/include/Rcpp/InputParameter.h:77:11: required from ‘class Rcpp::ConstReferenceInputParameter<Eigen::Matrix<double, -1, 1> >’
E> RcppExports.cpp:43:74: required from here
E> /home/taylor/R/x86_64-pc-linux-gnu-library/4.1/RcppEigen/include/Eigen/src/Core/DenseCoeffsBase.h:5
感谢您提供 URL 给重现者。这个错误,因为它经常发生,似乎是 'hidden' 更深的 devtools::document()
。
当我使用 'current everything' 从 CRAN 运行 Ubuntu 21.04 将您的存储库克隆到一台机器上并执行我通常的两步
compAttr.r # shell wrapper for Rcpp::compileAttributes
roxy.r -f # shell wrapper for roxygenize()
(使用我的小包中的这些帮助脚本), 我泪流满面,因为你的代码使用了 C++17 语句,却没有指定 C++17 作为编译标准。
换句话说,你这边的普通错误,独立于 Rcpp 或其他工具。
edd@rob:~/git/Whosebug/68985867/pfexamplesinr(master)$ compAttr.r
edd@rob:~/git/Whosebug/68985867/pfexamplesinr(master)$ roxy.r -f
ℹ Loading pfexamplesinr
Exports from /home/edd/git/Whosebug/68985867/pfexamplesinr/src/likelihoods.cpp:
double svolApproxLL(Eigen::Map<Eigen::VectorXd> y, Eigen::Map<Eigen::VectorXd> thetaProposal, Eigen::Map<Eigen::MatrixXd> uProposal)
Exports from /home/edd/git/Whosebug/68985867/pfexamplesinr/src/rcppeigen_hello_world.cpp:
Eigen::MatrixXd rcppeigen_hello_world()
Eigen::MatrixXd rcppeigen_outerproduct(const Eigen::VectorXd& x)
double rcppeigen_innerproduct(const Eigen::VectorXd& x)
Rcpp::List rcppeigen_bothproducts(const Eigen::VectorXd& x)
Exports from /home/edd/git/Whosebug/68985867/pfexamplesinr/src/resamplers.h:
Exports from /home/edd/git/Whosebug/68985867/pfexamplesinr/src/rv_eval.h:
Exports from /home/edd/git/Whosebug/68985867/pfexamplesinr/src/rv_samp.h:
/home/edd/git/Whosebug/68985867/pfexamplesinr/src/RcppExports.cpp updated.
/home/edd/git/Whosebug/68985867/pfexamplesinr/R/RcppExports.R updated.
Re-compiling pfexamplesinr
─ installing *source* package ‘pfexamplesinr’ ...
** using staged installation
** using staged installation
** libs
ccache g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppEigen/include' -fpic -g -O3 -Wall -pipe -pedantic -Wno-misleading-indentation -Wno-unused -Wno-ignored-attributes -Wno-class-memaccess -c RcppExports.cpp -o RcppExports.o
ccache g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppEigen/include' -fpic -g -O3 -Wall -pipe -pedantic -Wno-misleading-indentation -Wno-unused -Wno-ignored-attributes -Wno-class-memaccess -c likelihoods.cpp -o likelihoods.o
In file included from svol_sisr_hilb.h:8,
from likelihoods.cpp:1:
sisr_filter.h: In member function ‘void pf::filters::SISRFilter<nparts, dimx, dimy, resamp_t, float_t, debug>::filter(const osv&, const std::vector<std::function<const Eigen::Matrix<float_t, -1, -1>(const Eigen::Matrix<float_t, dimx, 1>&)> >&)’:
sisr_filter.h:229:16: warning: ‘if constexpr’ only available with ‘-std=c++17’ or ‘-std=gnu++17’
229 | if constexpr(debug)
| ^~~~~~~~~
sisr_filter.h:262:16: warning: ‘if constexpr’ only available with ‘-std=c++17’ or ‘-std=gnu++17’
262 | if constexpr(debug)
| ^~~~~~~~~
sisr_filter.h:288:16: warning: ‘if constexpr’ only available with ‘-std=c++17’ or ‘-std=gnu++17’
288 | if constexpr(debug)
| ^~~~~~~~~
sisr_filter.h:320:16: warning: ‘if constexpr’ only available with ‘-std=c++17’ or ‘-std=gnu++17’
320 | if constexpr(debug)
| ^~~~~~~~~
sisr_filter.h: In member function ‘void pf::filters::SISRFilterCRN<nparts, dimx, dimy, dimu, dimur, resamp_t, float_t, debug>::filter(const osv&, const arrayUs&, const usvr&, const std::vector<std::function<const Eigen::Matrix<float_t, -1, -1>(const Eigen::Matrix<float_t, dimx, 1>&)> >&)’:
sisr_filter.h:559:16: warning: ‘if constexpr’ only available with ‘-std=c++17’ or ‘-std=gnu++17’
559 | if constexpr(debug)
| ^~~~~~~~~
sisr_filter.h:592:16: warning: ‘if constexpr’ only available with ‘-std=c++17’ or ‘-std=gnu++17’
592 | if constexpr(debug)
| ^~~~~~~~~
sisr_filter.h:618:16: warning: ‘if constexpr’ only available with ‘-std=c++17’ or ‘-std=gnu++17’
618 | if constexpr(debug)
| ^~~~~~~~~
sisr_filter.h:650:16: warning: ‘if constexpr’ only available with ‘-std=c++17’ or ‘-std=gnu++17’
650 | if constexpr(debug)
| ^~~~~~~~~
In file included from likelihoods.cpp:2:
resamplers.h: In member function ‘void pf::resamplers::sys_hilb_resampler<nparts, dimx, num_hilb_bits, float_t>::resampLogWts(pf::resamplers::sys_hilb_resampler<nparts, dimx, num_hilb_bits, float_t>::arrayVec&, pf::resamplers::sys_hilb_resampler<nparts, dimx, num_hilb_bits, float_t>::arrayFloat&, const usvr&) [with long unsigned int nparts = 500; long unsigned int dimx = 1; long unsigned int num_hilb_bits = 5; float_t = double]’:
resamplers.h:1089:36: warning: ‘idx’ may be used uninitialized in this function [-Wmaybe-uninitialized]
1089 | tmpPartics[i] = sortedParts[idx];
| ~~~~~~~~~~~^
ccache g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppEigen/include' -fpic -g -O3 -Wall -pipe -pedantic -Wno-misleading-indentation -Wno-unused -Wno-ignored-attributes -Wno-class-memaccess -c rcppeigen_hello_world.cpp -o rcppeigen_hello_world.o
ccache g++ -std=gnu++14 -Wl,-S -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -flto=auto -Wl,-z,relro -o pfexamplesinr.so RcppExports.o likelihoods.o rcppeigen_hello_world.o -L/usr/lib/R/lib -lR
installing to /tmp/devtools_install_2dc74d5a52ad61/00LOCK-pfexamplesinr/00new/pfexamplesinr/libs
** checking absolute paths in shared objects and dynamic libraries
─ DONE (pfexamplesinr)
edd@rob:~/git/Whosebug/68985867/pfexamplesinr(master)$