Skip to content

Instantly share code, notes, and snippets.

@wch
Last active March 30, 2023 20:29
Show Gist options
  • Save wch/849ca79c9416795d99c48cc06a44ca1e to your computer and use it in GitHub Desktop.
Save wch/849ca79c9416795d99c48cc06a44ca1e to your computer and use it in GitHub Desktop.
How to deal with R-devel C++17 warning

How to deal with the SystemRequirements: C++11 NOTE when running R CMD check

For the development version of R-devel which will become 4.3.0, there is a new warning in R CMD check that comes up for some packages:

* checking C++ specification ... NOTE
  Specified C++11: please drop specification unless essential

(In earlier versions of R-devel, it said please update to current default of C++17.)

Link to the code that generates the NOTE.

CRAN is now asking to fix and resubmit packages which raise this NOTE.

This happens when the package's DESCRIPTION file has the following:

SystemRequirements: C++11

Packages that use C++11 generally would also have the following in the src/Makevars and src/Makevars.win files (and src/Makevars.ucrt, if present):

CXX_STD=CXX11

This tells R to use the C++11 standard when compiling the code.

To understand the NOTE, a bit of history will be helpful:

  • In R 3.5 and below, on systems with an old compiler, it would default to using the C++98 standard. If a package needed a C++11 compiler, the DESCRIPTION file was supposed to have SystemRequirements: C++11, and the src/Makevars, src/Makevars.win, and src/Makevars.ucrt files needed to have CXX_STD=CXX11. However, systems with newer compilers appear to default to C++11, even without setting CXX_STD.
  • In R 3.6.2, it defaulted to compiling packages with the C++11 (if the compiler supported C++11 -- and in practice, essentially all systems by that time had a C++11 compiler).
  • In R 4.0, it required a C++11 compiler, so SystemRequirements: C++11 was no longer necessary.
  • In (the forthcoming) R 4.3, it raises a NOTE if SystemRequirements: C++11 is present, which will block a package submission to CRAN.

How to fix it

  1. Edit the DESCRIPTION file and remove SystemRequirements: C++11.
  2. Edit src/Makevars, src/Makevars.win, and src/Makevars.ucrt and remove CXX_STD=CXX11.

After making these changes, the package should install without trouble on R 3.6 and above. However, on R 3.5 and below, there may be systems where it won't build (these are systems with very old compilers on them). Note that in my testing on GitHub Actions, with R 3.5 on Ubuntu 20.04 and 22.04, packages using C++11 build just fine. But on systems with older compilers, it could potentially be a problem.

If you want to be confident that your package to still be installable on R 3.5 and below with older compilers, then you need to use a configure script at the top level of the package, and have it add CXX_STD=CXX11 for R 3.5 and below.

@ateucher
Copy link

ateucher commented Feb 8, 2023

I think something like this would work if you don't already have src/Makevars/src/Makevars.win, or configure.R could be modified to write the entire contents if you do... Adapted from here.


If you require building on R <= 3.5.x, you must specify CXX_STD=CXX11 in
src/Makevars on those systems. One way to do this is to create the following files
that check the R version and if it < 3.6.2, sets that flag in Makevars. This assumes you
don't already have src/Makevars and/or src/Makevars.win already.

configure:

#!/bin/sh
exec "${R_HOME}/bin/Rscript" tools/configure.R

configure.win:

#!/bin/sh
exec "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" tools/configure.R

cleanup:

#!/bin/sh
rm -vf src/Makevars

cleanup.win:

cleanup

tools/configure.R:

if (getRversion() < '3.6.2') {
  fname = file.path('src', 'Makevars')
  f <- file(fname, 'wb')
  writeLines("CXX_STD=CXX11", f)
  close(f)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment