Chapter 6. Using the Two Languages Synergistically
Interoperability, the ability for different programming languages to work together, is a cornerstone of computing. Ideally objects can be shared directly between the two languages. As you can imagine, this can be problematic for a variety of reasons, like memory usage and incompatible data storage structures to name just two. Although there have been several attempts to implement this smoothly between Python and R, it’s only been in the past couple of years that a reasonably functional kit had come to fruition. I’ll discuss this in “Interoperability”. But it’s useful to first return to the basics. This will not only give context to appreciate smooth interoperability later on but also give you a basic solution that may already meet your needs. Nonetheless, if you want to get started with interoperability, you can skip the next section.
Faux Operability
The most basic type of interoperability, sometimes called cross-talk, is more of a faux operability. Here, we execute predefined scripts across languages, passing information between them using files as intermediaries. Imagine the following situation, which I’ve diagrammed in Figure 6-1.
In R, after performing some necessary work on an object, e.g., PlantGrowth
, we execute:
# (Previous interesting ...
Get Python and R for the Modern Data Scientist now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.