0

I use a C++ program, but I also R to prepare its inputs as well as to process its outputs (specifically formatted text files). It would be nice to call the Cpp program from within R, so the whole routine would be done in a single go. If I had a single function written in C++, I would learn how to use Rcpp package... but how to include a call to a compiled C++ program into an R script?

I would be grateful for any advice! All the best,

Ondrej

  • 2
    I think there is nothing special for `c++`. Probably you just need to execute an external program. I found [this page](https://stat.ethz.ch/R-manual/R-devel/library/base/html/system.html) – P. Dmitry Oct 07 '19 at 09:34
  • 1
    Honestly, I would say your best bet may still be to learn how to roll it into an R package using Rcpp. There are some advantages to that approach and it's not very difficult. However, it's really hard to say without knowing more about your problem. For example, what kind of data structures are you working with? Are you focused on calling a compiled program because you don't have access to the source code? Etc. – duckmayr Oct 07 '19 at 12:24
  • 1
    you mean a DLL ? – Stéphane Laurent Oct 07 '19 at 13:32
  • The function [system2](https://www.rdocumentation.org/packages/base/versions/3.6.1/topics/system2) proved to work well. Thanks to @P. Dmitry. I believe, however, the more principled would be to integrate the C++ code via Rcpp. – Ondřej Mikula Oct 08 '19 at 14:11

0 Answers0