Skip to content

Using R function in Excel

5 messages · John Sorkin, Uwe Ligges, Richard M. Heiberger +2 more

#
Does anyone know a way that an function written in R can be called within a cell of an Excel spreadsheet. I would like to use the R function much as I use the native Excel functions, e.g. instead of using the excel function sum, =sum(A2,A6), I would like to use the function mysum written in R, e.g. =mysum(A2,A6).

Thanks,
John 

John Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)

Confidentiality Statement:
This email message, including any attachments, is for th...{{dropped:6}}
#
See the R(D)COM Server (package "rcom") and RExcel from
http://sunsite.univie.ac.at/rcom/

Uwe Ligges
John Sorkin wrote:
#
You are looking for RExcel, which does exactly that.  Full documentation
and examples are included in the package.

http://sunsite.univie.ac.at/rcom/download/devel/

If you don't have R-2.6.1 yet, get the whole R system with
the RExcel installed

RAndFriendsSetup2061V1.82.exe


Otherwise, just get the RExcel installer, either

RExcel.installer_1.80-18.zip

or

RExcel.installer_1.80-18.tar.gz


Also look at the main RExcel/rcom site
http://sunsite.univie.ac.at/rcom/
and consider joining the mailing list there.
#
John Sorkin wrote:
Take a look at
R/Scilab (D)COM Server V2.50 and RExcel V1.75 found at
http://cran.r-project.org/other-software.html

I have experimented with it for non R users to run basic R functions or 
custom models.  I like theI did find a problem with the VBA math 
function calls in the xla file on the computer that I was using.  I just 
added VBA. to all the left, mid, etc functions.


I can provide my modified .xla file if you wanted it.

Happy Holidays
Joe
#
Dear John,

The R Workbench (biocep project) comes with a powerful Spreadsheet view
fully connected to an R session. you can use it to do exactly what you
want and it has much more features :

 from within the spreadsheet view you can :
        *import any R Data (numeric, integer, character, logical, complex,
factor, matrix, data frame ) via the toolbar button import from R
(R+arrow towards the spreadsheet)
        *export selected cells to R and assign the content of the cells to
an R variable via the toolbar button export to R (R+arrow towards
R)
         you specify the type of export (numeric, integer, character,
logical, complex, factor, data frame )
         for data frame, you should append to the column name the type of
the column between parathesis ("weight(integer)",
"mesure1(numeric)", "state(factor)", ..)
        * Evaluate an R expression and use the current selection as
argument (the toolbar button R evaluate (R+ruuning man))
         for example you can type "t(%%)" in the R Expression field. This
transposes the selected cells matrix. The result is sent to the
clipboard and you can paste on will
        * type in a cell an expression to evaluate and use any R fucntion,
example in A4 type "=mean(A1:A3)" the content of A4 will be
computed using R fucntion mean and the
         cell value will be the mean of the vector A1:A3. all the R
functions dealing with numeric vectors or matrixes can be used
        * Copy/Paste to and from Excel
        * create as many SpreadSheet Views as needed and specify the
suitable dimensions

on windows and Mac OS, you can use this link to install the R Workbench
http://www.ebi.ac.uk/microarray-srv/frontendapp/rworkbench.jnlp

for more information :
http://www.ebi.ac.uk/microarray-srv/frontendapp/BIOCEP_README.txt

Karim