11 C and Fortran code

If the package contains C or Fortran code, it should adhere to the standards and methods described in the System and foreign language interfaces section of the “Writing R Extensions” manual.

We emphasie particular points in the following sections.

11.0.1 Internal functions

Use internal functions, e.g., R_alloc and random number generators (RNGs), over system-supplied ones.

11.0.2 C function registration

Use C function registration (See the Registering native routines section of the “Writing R Extensions” manual).

11.0.3 Checks for user interruption

Use R_CheckUserInterrupt() in C level loops when there is a chance that they may not terminate for certain parameter settings or when their run time exceeds 10 seconds with typical parameter settings, and the method is intended for interactive use.

11.0.4 Makevars

Make judicious use of the Makevars and Makefile files within a package. These are often not required at all (See the Configure and cleanup section of the “Writing R Extensions” manual).

11.0.5 Warnings and optimizations

During package development, enable all warnings and disable optimizations. If you plan to use a debugger, tell the compiler to include debugging symbols.

The easiest way to enforce these is to create a user-level Makevars file user’s home directory in a sub-directory called ‘.R’). See examples below for flags for common toolchains. Consult the section about Makevars files in the Writing R Extensions Manual manual.

Example for gcc/g++:

CFLAGS=-Wall -Wextra -pedantic -O0 -ggdb
CXXFLAGS=-Wall -Wextra -pedantic -O0 -ggdb
FFLAGS=-Wall -Wextra -pedantic -O0 -ggdb

Example for clang/clang++:

CFLAGS=-Weverything -O0 -g
CXXFLAGS=-Weverything -O0 -g
FFLAGS=-Wall -Wextra -pedantic -O0 -g