

Otherwise you have an Intel Mac, so you’ll want the version built for the high-sierra OS, which works on any macOS >=10.13. If you have an M1 Mac, then you’ll probably want the version built for the big-sur OS. You’ll probably want the build that looks something like R-4.1-branch. To get around this, you can download a non-notarized and unhardened version of R for macOS from here instead. The R that you typically download is a notarized application, so it falls in this category. The R for macOS FAQ has a bullet point named “I cannot attach a debugger to R.” This is particularly relevant for us, as it explains that new Apple computers require that all notarized applications use a “Hardened Runtime”, which ends up meaning that those applications can’t be utilized with a debugger like lldb. If you aren’t using a Mac, the absolute paths set in the configuration files below will need to be updated! Non-notarized R R 4.1.1 ( Non-notarized! See the next section.).

It is worth noting my personal setup, as the finer details of this post will vary a bit per operating system: If you are a VS Code expert and notice anything incorrect in this post, feel free to open an issue to help us improve it! My specs I have also had many discussions with and insights from Jenny Bryan while trying to get this to work smoothly. While this post doesn’t take the exact same approach as his, it was still invaluable for getting started. Most of this post would not be possible without the work of Kun Ren, who has a nice post on VS Code Extensions for R and an example repo on using VS Code with cpp11. This post assumes a little working knowledge of lldb. If you haven’t yet read my post about using lldb (linked above and again here), then I’d encourage you to do that first, as it explains some of the basics and gotchas of using lldb with R. In the remainder of this post, I’ll show how to set up VS Code to debug an R package containing C++ code, which should hopefully make this tool more accessible to the R community. Unsurprisingly, the C++ community has built a number of tools that do have support for this, one of them being VS Code with C++ extensions, but the R community hasn’t latched on to any of these yet.

While this works, it lacks the elegance and ease of use that we typically expect from a full fledged debugger, i.e. setting breakpoints by clicking on the line we care about, clicking to step over or into functions, easily watching local variables change, etc. In a previous post, I’ve talked about how to use lldb to debug an R package with C++ code. RStudio is a fantastic IDE for R code, and has an amazing debugger built in, but sometimes you need to use a different tool for debugging C++ code. This post is intended to serve as a reference for R package developers that use C or C++ code inside their package.
