• If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Stop wasting time looking for files and revisions. Connect your Gmail, DriveDropbox, and Slack accounts and in less than 2 minutes, Dokkio will automatically organize all your file attachments. Learn more and claim your free account.



Page history last edited by PBworks 14 years, 7 months ago

One thing that was great was the ability to copy to and from the clipboard:


  • scan('clipboard')


  • x=rnorm(10); write.table(x, file='clipboard', sep='\t')


This makes getting data in from and to excel particularly quick. Good if you want to do a speedy analysis and dont want to set up a more permanent structure.


R and Excel


We showed in a little spreadsheet how you can embed R functions in Excel.

To run this example you need the R-Excel Addin, from here. Please read the documentation that comes along with the Addin and see the examples as well.


The key idea is, that you write a little warpper in VB around your R code.

Open the Visual Basic editor (press Alt F11 while in Excel) and go to ThisWorkbook and copy and paste


Private Sub Workbook_Open()

Call RInterface.StartRServer

End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Call RInterface.StopRServer

End Sub



into it.

This will open the R server in the background whenever you open the workbook and the second procedure will stop the R server when you close the workbook.

You have to make a reference to the "RExcelVBAlib" (goto Tools\References... and tick RExcelVBAlib) so Excel knows those functions.


In a new module we create now our RExcel function. Let's reinvent the wheel and programm the "SUM" function again:


Function rSum(Helmut As Range) As Variant

Call Rput("rHelmut", Helmut)

Call RInterface.RRun("X<-sum(rHelmut)")

rSum = reval("X")

End Function


That's it! You can use rSum now in the same way as the SUM function of Excel.

Here is a spreadheet containing the example of this site.

Comments (0)

You don't have permission to comment on this page.