chapter  14
18 Pages

An Interface to Python

ByJohn M. Chambers

This chapter describes the use of the interface in an application extending R. The application will likely implement an R package using the interface to carry out some computations in Python and incorporating those computations into software for the users of the application. Python computations consist mainly of function calls and the use of methods and fields in objects from Python classes. These are available directly through methods for an interface evaluator or equivalent function calls. Additional methods and function calls provide interfaces to other Python programming that is likely to be needed, such as importing modules. Data conversion facilities are available when needed including the representation of arbitrary R objects in Python and the return of arbitrary Python objects to R. Python implements encapsulated object-oriented programming by class definitions in the language, containing a set of method definitions. Evaluating the definition creates a corresponding class object.