I would like to know if I could call R function already created in R script inside Qt push button.
As Qt is based on C++ language. I know that I can use "RInside" and "Rcpp" libraries to run R inside C++ code. However, this require changing the R function to be compatible with C++ format. In my case, my R functions are already in R script and I do not want to change them or re-write them in R-C++ format.
Is there a way to call the function directly without rewrite it in C++ format?
Usually you already know the answer yourself, you just need to ask yourself the right question:
"How would this work, without changing the C++ compiler?"
C++is a compiled language, meaning that any application that you write inC++needs to be compiled into a binary file. The language itself is nothing but instructions for the compiler on what you expect to be the final result.Looking at rinside on github it is pretty straightforward how to implement your function in C++ using it. And this is to an extent your only option. Here's why:
Scripting languages like
PythonandRwork in a way that they have a main application called aninterpreterwhich you instruct using the aforementioned scripting language on how to call existing functions from (usually)C/C++libraries. That means that if you write a function inRthen you just define a "recipe" for theR interpreteron how it should (sequentially) call these library functions. But your function itself IS NOT PART of said library.That being said I do not think it is possible to do what you ask, because most likely
rinsidejust takes advantage of the already existing libraries used by theR interpreterand makes them accessible via an interface inC++.Your best option is reconstructing the function you made in
C++usingrinsidewhich looks very user friendly.There is another option and that is that you would wrap the entire
Rapplication and make it part of theC++ application(i.e. you open it from your application and stream your commands into it) but that is much more complicated than just rewriting your function.EDIT: Just a small note, the
rinsidelibrary is co-authored by @Dirk Eddelbuettel with whom I had a chance to have a pleasant discussion on Stackoverflow. If you would've addrcpp,rinsideorcranas a tag to your question. You would've most likely get an answer straight from an expert in this area.