Embed an R process in a VBA macro Embed an R process in a VBA macro vba vba

Embed an R process in a VBA macro


I am unfamiliar with r process, but this link appears to be valid for your question.

http://www.unt.edu/rss/class/splus/UsingRWithinExcel.pdf

RExcel - Using R from within Excel

Overview

The Excel addin RExcel.xla allows to use R from within Excel. The package additionally contains someExcel workbooks demonstrating different techniques for using R in Excel.There are two types of servers, forground and background. The background server ist totally hidden from theuser, all interaction with R has to be done in Excel. The foreground server allows direct access to the R GUIcommand line while working in Excel. The backgound server is installed with the R(D)COM server, thebackground server depends on the {R}-package rcom, which has to be installed >from CRAN.

Usage

There are at least three different ways of using R from within ExcelScratchpad modeWriting R Code directly in an Excel worksheet and transferring scalar, vector, and matrix variablesbetween R and Excel

Macro mode

Writing macros using VBA and the macros supplied by RExcel.xla, attaching the macros to menuitems or toolbar items

Worksheet functions

R can be called directly in functions in worksheet cells

Scratchpad Mode

The RExcel menu contains the following items:

R Start

Initiates a connection to RIf necessary starts an R process to be accessed >from ExcelFor the details of executing code at startup see section Startup

Close R

When this process is running, R Start changes to Close RRun CodeSelecting a range (only one column wide) in Excel containing valid R code and then choosing thismenu item executes the selected code

Get

Gets the value of an R variable into the active Excel cell or rangePossible values are scalars and matrices of numbers or strings, or dataframes.

Put

Puts the values of the selected Excel range into an R variable.Possible values are scalars and matrices of numbers or strings, or dataframes.If a dataframe is to be put, the first row of the Excel range must contain the variable names for thedataframe.Put for dataframes only transfers data in visible rows and columns, hidden rows and columns will notbe transferred.

Copy Code

Puts the content of the selected range on the Windows clipboard, assuming that it is R code, and wrapsthe code in VBA procedure calls to make it ready for inclusion in VBA macros


RExcel, a free add-in for Excel that can be downloaded from the R distribution network. RExcel seamlessly integrates the entire set of R's statistical and graphical methods into Excel.

The book R Through Excel offers a good entry for those just beginning with R through the familiar Microsoft Excel..