Chapter 7 System and foreign language interfaces
7.1 Operating system access
Access to the operating system shell is via the R function
system. The details will differ by platform (see the on-line help), and about all that can safely be assumed is that the first argument will be a string
command that will be passed for execution (not necessarily by a shell) and the second argument will be
internal which if true will collect the output of the command into an R character vector.
Sys.getenvOS environment variables
A uniform set of file access functions is provided on all platforms:
There are also functions for manipulating file names and paths in a platform-independent way.
File name without directory
Construct path to file
~in Unix path
7.2 Foreign language interfaces
See System and foreign language interfaces in Writing R Extensions for the details of adding functionality to R via compiled code.
.Fortran provide a standard interface to compiled code that has been linked into R, either at build time or via
dyn.load. They are primarily intended for compiled C and FORTRAN code respectively, but the
.C function can be used with other languages which can generate C interfaces, for example C++.
.External provide interfaces which allow compiled code (primarily compiled C code) to manipulate R objects.
7.3 .Internal and .Primitive
.Primitive interfaces are used to call C code compiled into R at build time. See .Internal vs .Primitive in R Internals.