Developing C/C++ code for R with Positron: Part 1

submited by
Style Pass
2024-10-28 13:30:08

Positron is a new IDE by the creators of RStudio that’s built on VSCode’s open source core, but layered with extra bells and whistles for R (and Python, if that’s your thing). And those bells and whistles’ music is particularly well tuned for R developers working with compiled code, which was always a rather rough experience in RStudio. As someone who basically uses R as a nice LISP-y scripting language to orchestrate calling low-level compiled code from other languages, this is a very welcome addition to the R ecosystem for the following reasons:

This was one of Positron’s standout features when it was unveiled at Posit::conf(2024): the R session is no longer tightly bound to the IDE. This means that when R crashes due to an out-of-bounds memory access or something similar, the entire IDE doesn’t go up in flames—just the R session. A much nicer developer experience, particularly if you like to play fast and loose with pointers.

VSCode has great extensions for C++ code that make development much, much easier. For example, the extension clangd analyzes your C++ code and provides real-time feedback, without having to compile your code. You can use it to catch errors, perform code refactoring, and even check the size of structs (including automatically inserted padding!). Need to fit a struct into a cache line? clangd can help you know exactly how your data is laid out in memory. You just need to install the extension and generate a compilation database using pkgload:::use_compilation_db() to get started.

Leave a Comment