1

I am wondering if there was a workaround for using the R package Rcpp within a Visual C++ project within Visual Studio. According to the Rcpp FAQ, this is not possible. I also came across another R package called R.NET. Can this only work with C# but there seems to be no examples from within Visual C++? Is there another option for this that I am missing? Even if I am forced to work with C#, can anyone envision latency issues with this for a high frequency trading environment? Thanks for any feedback

0

3 Answers 3

6

We address this very question clearly in the Rcpp FAQ (which comes as vignette in the package, is on the CRAN site and its mirrors, and on my website).

In short, Rcpp supports the exact same toolchain which R supports. And on Windows that is MinGW (the port of gcc to Windows) provided by the Rtools package for R.

R Core only support MinGW, and we do the same. If one could compile R with Visual Studio, things would be easier, but as Rcpp sits on top of R we are playing the hand we are dealt with.

So sorry, the answer is a "No" to Visual Studio.

2
  • This sucks. Started writing native extensions for R in gfortran then got these errors where my R would crash. Spent two days trying to debug .. no luck. So I switched to C++ Visual Studio (because of the debugging capabilities) and now discovering R and VS don't play well together. So now what? Abandon R and go to Python? Sep 11, 2019 at 15:00
  • Develop code in VS as usual, use the Windows toolchains that has been using for 20+ years (and which are a given for the Rcpp team as well -- we don't get tp pick either). Sep 11, 2019 at 15:45
2

The question is what you really want to connnect with what. If you want to use R within C++ Rcpp seems to be the wrong decision as it connects C++ to R (and not the other way round as your question implies.).

If you want to connect R to C++ and use Visual C++ for creating your C++ code only (instead of linking R to C++), you might want to check this recent blog post (found via R-bloggers.com). It tells you a possible way of doing so.

2

Visual Studio works just fine with Rcpp. Has done for years. I disagree with Dirk Eddelbuettel.

This is an important fact - For example, there are very important libraries (Intels MKL, QT graphics framework) which are actually not compatible with minGW.

I maintain a (patched and cut-down) fork of Rcpp on github (https://github.com/rohan-shah/Rcpp) suitable for compilation with Visual Studio with cmake. The patch is something like five lines, I believe.

Disclaimer: It's fiddly to use, and you have to know what you're doing. If you do know what you're doing though, I've done quite a bit of the work for you. See https://github.com/rohan-shah/mpMap2 for an example of how to use patched Rcpp with Visual Studio.

4
  • This will always be very fiddly to use for as long as R itself does not proprely support this compiler. As such, "no support" from Rcpp either. If you know what you're doing and are hell-bent, you know what to do. Rest of your post here plain false as Qt can be used just fine with MinGW (and I have done so 10 years ago when I still work on Windows). See RInside too. Sep 27, 2017 at 10:46
  • I'm so happy that it worked ten years ago. What about today? MinGW is supported by QT only for 32-bit, which for all intents and purposes means that it's not supported. You can try and build it from source from 64-bit - I certainly couldn't make it work. To quote you back at yourself, this will always be very fiddly to use for as long as QT itself does not properly support this compiler. Why can you not accept that this is actually a legitimate solution to a software problem? Do you think I didn't consider the alternatives?
    – DaBookshah
    Sep 27, 2017 at 14:41
  • 1) Qt supports MinGW out of the box: wiki.qt.io/MinGW. 2) As I said before, Rcpp uses what R supports as a toolchain, and as long as R has no support for VS you are barking at the wrong tree---talk to R Core. 3) Your attitude is such that I have limited interest in engaging with you. Sep 27, 2017 at 14:44
  • (And for what it is worth, yes, I did build Qt from source back then when to support an integration with R. Painful, but possible. But there are reasons people turn away from Windows as a development platform.) Sep 27, 2017 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.