sourceCpp()无法获取此文件的源代码

sourceCpp() fail to source this file

本文关键字:文件 源代码 获取 sourceCpp      更新时间:2023-10-16
编译此文件时,警告"无效转换…const int"。有人能说出哪里出了问题以及如何解决吗。谢谢
#include <Rcpp.h>
using namespace Rcpp;
//[[Rcpp::export]]
IntegerVector ats(SEXP p, SEXP rolsd, SEXP sig, SEXP b)
{
  Rcpp::NumericVector loc_p(p);
  Rcpp::NumericVector loc_rolsd(rolsd);
  Rcpp::IntegerVector signal(sig);
  int n=loc_p.size();
  int m=signal.size();
  float bb = Rcpp::as<float>(b);
  Rcpp::IntegerVector result[m];
  for(int j=0;j<m;j++)
  { 
    int i=0;
    float  ma=loc_p[j];
    while(loc_p[i+signal[j]] >= (1-loc_rolsd[i+signal[j]]*bb)*ma & i<=n-signal[j])
    {
      i=i+1;
      if(ma < loc_p[i+signal[j]]) ma = loc_p[i+signal[j]];
    }
    result[j]=i;
  }
  return result;
}

请检查while语句。

while(((loc_p[i+signal[j]]) >= ((1-loc_rolsd[i+signal[j]]*bb)*ma)) && (i<=n-signal[j]))
    {
      i=i+1;
      if(ma < loc_p[i+signal[j]])
         ma = loc_p[i+signal[j]];
    }

我认为你也必须核实这份声明。

Rcpp::IntegerVector result[m];

而声明array需要Constant Value,所以您需要声明为

Rcpp::IntegerVector result[10]; // where m should be any int const value希望这对你有帮助。