0

I have a user-defined object returned from a c++ function, which is accessed in an R-code using Rcpp library in Rstudio.

When the R package is built and deployed on opencpu using 'R CMD INSTALL' the g++ compiler throws an error: ‘Result’ does not name a type.

'Result' is a c++ class which is returned by the c++ code to the calling R-code. I think R does not recognise this c++ class, but displays the Result class when typing for auto completion.

I dont understand why the command 'R CMD INSTALL' does not execute and install as expected.

The rcpp.c file

#include <Rcpp.h>
#include "Engine.h"
#include "Result.h"
using namespace Rcpp;
using Engine::execute;
// [[Rcpp::export]]
List rcpp_hello_world() {

    CharacterVector x = CharacterVector::create( "foo", "bar" )  ;
    NumericVector y   = NumericVector::create( 0.0, 1.0 ) ;
    List z            = List::create( x, y ) ;

    return z ;
}

// [[Rcpp::export]]
Result execute(){
  printf("In cpp call!!");
  ForecastingModel *fm;
  InputData *sid;
  int i=1;
  int j=1;
  utils::Time *startTime;
  utils::Time *endTime;
  return Engine::execute(*fm,*sid,i,j,*startTime,*endTime);
}

c++ file

#ifndef RESULT_H
#define RESULT_H

#include<string>
#include<vector>
class Result
 {
 private:

   int status ;
   std::vector<double> forecast;
   std::string dataproblem ;
  public:

  std::string getDataproblem( );
  void setDataproblem(std::string);
  void setForecast(std::vector<double> );
  std::vector<double>& getForecast();
  int getStatus( );
  void setStatus(int);
 };
 #endif

Any help is appreciated. Thanks!

  • It is probably not the solution to your problem, but including code files (.c/.cpp) insteadof headers (.h/.hpp) is usually a path to trouble. – Yunnosch Aug 09 '18 at 05:18
  • @Yunnosch tried that but same error.... – Nadeem Iqbal Saif Aug 09 '18 at 05:39
  • 1
    Need to write the converter logic to go from a C++ object to an R object for the ‘Result’ class. See extending Rcpp vignette and the custom as / wrap post on the Rcpp gallery for examples. – coatless Aug 09 '18 at 06:32
  • 1
    Is your package in a GitHub repo so that we can reproduce the issue? – F. Privé Aug 09 '18 at 06:43
  • 1
    I'm with @RalfStubner -- I think you want to go for returning a named List as in his answer to the question he's suggested for a duplicate. – duckmayr Aug 09 '18 at 10:46
  • "`Result` does not name a type" is _as precise as it can get_ because you first have to tell the compiler how to map your `Result` type to the `SEXP` type R needs, – Dirk Eddelbuettel Aug 09 '18 at 13:51
  • @DirkEddelbuettel could you please guide me how to map my user defined object to SEXP type in R. – Nadeem Iqbal Saif Aug 30 '18 at 09:07
  • There are 1) an entire vignette shipping with Rcpp that explains it (and a corresponding chapter in the Rcpp book), 2) several examples at the Rcpp Gallery, and 3) several questions here. And it does not lead itself to a 20 word answer for a comment here. Please try to look into the existing documentation and examples. – Dirk Eddelbuettel Aug 30 '18 at 12:35

0 Answers0