Неустранимая ошибка для ‹RInside.h›

Я запускаю этот пример через терминал. Но получил fatal error: RInside.h: No such file or directory ошибку для строки #include<RInside.h>. Это интерфейс к R из С++. У меня есть пакет RInside в R. Мой код:

#include<iostream>
#include<RInside.h>
using namespace std;
int main(){
    int a=12;
    cout<<a<<endl;
    return 0;  
}

Такая же ошибка произошла для заголовка #include<Rcpp.h>.

#include <Rcpp.h>

using namespace Rcpp;

// [[Rcpp::export]]
NumericVector callFunction(NumericVector x, Function f) {
    NumericVector res = f(x);
    return res;
}

Пакет RInside версии 0.2.14

Пакет Rcpp версии 0.12.17


person 9113303    schedule 27.06.2018    source источник
comment
Найдите эти заголовки в вашей файловой системе и убедитесь, что они видны компилятору (они находятся в списке путей, которые компилятор проверяет на наличие заголовков). Кроме того, какая ОС?   -  person schaiba    schedule 27.06.2018


Ответы (2)


GNUmakefile, поставляемый с RInside в папке examples, включает в себя такие вещи, как:

## comment this out if you need a different version of R, 
## and set set R_HOME accordingly as an environment variable
R_HOME :=       $(shell R RHOME)

[...]
## include headers and libraries for R 
RCPPFLAGS :=        $(shell $(R_HOME)/bin/R CMD config --cppflags)
RLDFLAGS :=         $(shell $(R_HOME)/bin/R CMD config --ldflags)
RBLAS :=        $(shell $(R_HOME)/bin/R CMD config BLAS_LIBS)
RLAPACK :=      $(shell $(R_HOME)/bin/R CMD config LAPACK_LIBS)

## if you need to set an rpath to R itself, also uncomment
#RRPATH :=      -Wl,-rpath,$(R_HOME)/lib

## include headers and libraries for Rcpp interface classes
## note that RCPPLIBS will be empty with Rcpp (>= 0.11.0) and can be omitted
RCPPINCL :=         $(shell echo 'Rcpp:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)
RCPPLIBS :=         $(shell echo 'Rcpp:::LdFlags()'  | $(R_HOME)/bin/R --vanilla --slave)


## include headers and libraries for RInside embedding classes
RINSIDEINCL :=      $(shell echo 'RInside:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)
RINSIDELIBS :=      $(shell echo 'RInside:::LdFlags()'  | $(R_HOME)/bin/R --vanilla --slave)

## compiler etc settings used in default make rules
CXX :=          $(shell $(R_HOME)/bin/R CMD config CXX)
CPPFLAGS :=         -Wall $(shell $(R_HOME)/bin/R CMD config CPPFLAGS)
CXXFLAGS :=         $(RCPPFLAGS) $(RCPPINCL) $(RINSIDEINCL) $(shell $(R_HOME)/bin/R CMD config CXXFLAGS)
LDLIBS :=       $(RLDFLAGS) $(RRPATH) $(RBLAS) $(RLAPACK) $(RCPPLIBS) $(RINSIDELIBS)

Если вы используете GNU make, вы, вероятно, можете использовать это буквально. В противном случае вам придется адаптировать его для вашей среды сборки. Пожалуйста, ознакомьтесь с приведенными примерами для более подробной информации.

person Ralf Stubner    schedule 27.06.2018
comment
Я пробовал это. stackoverflow.com/a/21225890/9113303 через R studio и во время работы я только что получил Rcpp::sourceCpp( 'Desktop/cuda_pgm_cpp/mySum.cpp') в качестве вывода, но как получить возвращаемые значения. Я передаю 2 параметра через функцию. - person 9113303; 27.06.2018
comment
@Aswathy Какое отношение к этому вопросу о RInside? Что вы пытаетесь сделать явно? - person Ralf Stubner; 27.06.2018
comment
: Попытка вызвать функцию R из C++ (с передачей аргументов). Для этого Rcpp и RInside являются полезными пакетами. - person 9113303; 27.06.2018
comment
@Aswathy Вы просматривали примеры, которые идут с RInside? Если они не содержат достаточно подробностей, вам следует предоставить минимальный воспроизводимый пример того, что вы пытаетесь сделать. - person Ralf Stubner; 27.06.2018

Вы должны указать путь к заголовочному файлу при компиляции RInside с помощью g++. Для справки есть список параметров g++ в Mac OS X (10.14.2 Mojave), надеюсь, это поможет.

g++ 
-I/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RInside/include \
-I/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include \
-I/Library/Frameworks/R.framework/Versions/3.5/Resources/include \
-L/Library/Frameworks/R.framework/Versions/3.5/Resources/lib \
-L/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RInside/lib \
-lR -lRInside -O3 -o test helloworld_rinside.cpp

исходный код "helloworld_rinside.cpp", http://dirk.eddelbuettel.com/code/rinside.html

// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4;  tab-width: 8; -*-
//
// Simple example showing how to do the standard 'hello, world' using embedded R
//
// Copyright (C) 2009 Dirk Eddelbuettel
// Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois
//
// GPL'ed

#include <RInside.h> // for the embedded R via RInside

int main(int argc, char *argv[]) {

  RInside R(argc, argv); // create an embedded R instance

  R["txt"] = "Hello, world!\n"; // assign a char* (string) to 'txt'

  R.parseEvalQ("cat(txt)"); // eval the init string, ignoring any returns

  exit(0);
}
person madeinQuant    schedule 03.02.2019