Mixing R, Python, and Perl in 14 lines of code

This is a continuation of my previous post, Running Python and R inside Emacs. That post shows how to execute independent code blocks in Emacs org-mode. This post illustrates calling one code block from another, each written in a different language.

The example below computes sin2(x) + cos2(x) by computing the sine function in R, the cosine function in Python, and summing their squares in Perl. As you’d hope, it returns 1. (Actually, it returns 0.99999999999985 on my machine.)

Apparently each function argument has to have a default value. If that’s documented, I missed it. I gave the sine and cosine functions default values that would cause the call to sum_sq to return more than 1 if the defaults were used.

Post navigation

4 thoughts on “Mixing R, Python, and Perl in 14 lines of code”

In what way does this post illustrate calling one code block from another, whatever language they’re written in? It seems to me to show code blocks in each of three languages followed by an expression in its own little language which calls each of those in turn. There doesn’t seem to be any call from one code block to another. Have I missed something?