Calling R/Python directly from Excel
In this section, we will dig into the ways you can call R and Python from Excel using the tools set up in the previous section. We will cover several ways of achieving this and give examples so that you can try them out as well.
Executing R with VBA and BERT
Another great way of calling R from Excel is via the VBA macro. This requires that a workbook be saved as a macro-enabled workbook. Since BERT is designed to work from Excel to R, the syntax of an R expression can be written in the VBA console and called with the following in VBA:
Application.Run "BERT.Exec", r
Let’s look at an easy example:
Sub PlotNormalDensity() Â Â Â Â r = "plot(density(rnorm(1000)))" Â Â Â Â Application.Run "BERT.Exec", r End Sub
This will end up producing a plot of the density of a random normal distribution. Let’s see the output:
Figure 11.4 –...