1

C++ ライブラリlibsbml::Modelのタイプのオブジェクトを Rcpp ベースのパッケージで返そうとしています。libsbml

最後に、パッケージでこのようなことができるようにしたいR

m <- getModel("text.xml")
m$getListofParameters

モデルを返すために次のことを試みています

// [[Rcpp::export]]
SEXP getModel (std::string fname) {

  libsbml::SBMLReader reader;
  libsbml::SBMLDocument* document = reader.readSBMLFromFile(fname);

  libsbml::Model* model = document->getModel();

  // Rcpp::XPtr<libsbml::Model> modelPtr(model);
  // return Rcpp::wrap(modePtr);

  return Rcpp::wrap(*model);

}

それは私に明らかなエラーを与えています、 cannot initialize a variable of type "SEXP' (aka 'SEXPREC *') with an lvalue of type 'libsbml::Model *const'

おそらく、ギャラリーの最近の記事に基づいて、wrap戻り型に拡張する必要があるためです (と思います)。私はこの考え方で正しい軌道に乗っていますか? は巨大なクラスであり、私はオブジェクト指向プログラミングの経験がない C++ の初心者であるため、巨大なタスクのように思えます。libsbml::ModelRcpplibsbml::Model

次のコードも試しました(Rcppモジュールを使用)

RCPP_MODULE(sbModel){

  using namespace Rcpp ;

  // we expose the class libsbml::Model as "Model" on the R side
  class_<libsbml::Model>("Model")

    // exposing the default constructor
    .constructor<unsigned int, unsigned int>("Creates a new Model using the given SBML level and version values.")

    // exposing member functions -- taken directly from libsbml::Model
    .method( "getListofParameters", &libsbml::Model::getListOfParameters(),"Get the list of Parameters of the model")

}

libsbml::Modelクラスのメソッドのいくつかを公開するため。しかしClean and Rebuild、パッケージのコマンドで次のメッセージが表示されます

call to non-static member function without an object argument

漠然とした質問で申し訳ありませんが、そのクラスのいくつかのフィールドにエクスポートlibsbml::Modelして公開するという私の最終目標を達成する方法についての指針をいただければ幸いです。Rコードの最終バージョンは -

https://github.com/sn248/Rcppsbml/blob/master/src/getModel.cpp

4

0 に答える 0