how to call function from another file in Rcpp?

HOw to call Rcpp function in my another Rcpp file like mean.cpp call this mean fun in my another file OR Should i write all function in my one file .cpp file?

You need the function declaration if you want to call it from another file. The most usual approach would be to put the function declaration into a header file (.h) and include that header in both the file that defines the function as well as in the files that want to call the function.

I have three function suppose mean.cpp, median.cpp, mode.cpp in Folder(Descr Stat). Can i export(Rcpp::export) all three by write only one Rcpp files(descr_stats.cpp) So that i can call sourceCpp("descr_stats.cpp"). Is it possible?

Yes, this is possible. You have to write a header file for every C++ file from which you want to include a function. These header files must than be included in your main file. See section "1.10. Sharing Code" in the Rcpp Attributes vignette for more details. However, when your project has reached a size that warrants multiple files, it also warrants creating a package for it.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.