问题
I have long used Rcpp with Rstudio, but recently I lost autocomplete and diagnostic functionality.
I was able to trace the cause to RcppArmadillow.
Here is the basic default c++ new file code with modifications.
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::export]]
NumericVector timesTwo(NumericVector x) {
return x * 2;
}
// [[Rcpp::export]]
double GetValueAt(const NumericMatrix& x, int row = 1, int col = 1) {
return x(row-1,col-1);
}
/*** R
timesTwo(42)
GetValueAt(as.matrix(42),1,1)
*/
This code works and executes correctly. // [[Rcpp::depends(RcppArmadillo)]]
even though its commented out is needed and if it is removed or double commented, the code fails at the x(row-1,col-1);
referance.
I am using .rs.setClangDiagnostics(2)
for clang diagnostics and I get the following error for running code:
error: OpenMP support and version of OpenMP (31, 40 or 45) was disabled in PCH file but is currently enabled
And it seems this error is why completion fails.
This has been asked online before, such as here: https://community.rstudio.com/t/rstudio-does-not-display-correct-c-diagnostics-libclang-error/26439, https://community.rstudio.com/t/rcpparmadillo-code-completion/41736 https://github.com/rstudio/rstudio/issues/4685
But it does not look like any of them have a solution that I can replicate. I do not know how I can change PCH file settings or otherwise.
I am using Windows 7 64 bit. R 3.5.3, Rstudio 1.2.5033, with Rtools 3.5 compiler, RcppArmadillo 0.9.850.1.0, All recently updated except R itself.
Code completion does work with just Rcpp and without Armadillo, but basic NumericMatrix functionality is lost. I would like some way to get completion back, either with Armadillo, or get my code to compile with Rcpp and not Armadillo. Thank you.
来源:https://stackoverflow.com/questions/60528683/rstudio-no-autocomplete-with-rcpp-armadillo