[R] Export the R object

Eugene emelamud at yahoo.com
Sat Jan 1 19:12:03 CET 2005


If you do a lot of exports from R to excel, you might want to use 
a wrapper function around write.table(). I got tired of using 
write.table(), go to excel, select file and load routine. 

My solution to the problem is to create a simple function that
opens excel spreadsheet automatically from R. The function
exports R data.frame into temp file, and calls excel with temp
filename. It saved me a lot of time. 
 
An example: 
> excel(mymydataframe

Here is the function: ( you might have to change path to the excel 
executable )

excel <- function(x) {
   #create a temp filename
  tmpfilename <-paste(tempfile(c("abs")),".csv",sep="");

   #export table in comma seperated by ,
    write.table(x, file=tmpfilename, sep=",");
	         
   #run excel as a background process
   system( paste('"C:\PROGRAM FILES\MICROSOFT OFFICE\OFFICE\EXCEL.EXE"', tmpfilename ),
wait=FALSE);

   #sleep 5 seconds, this is done to insure that R doesn't delete the file before excel opens it
    Sys.sleep(5);
       unlink(tmpfilename);
}

Hope this helps. 
Eugene MeMelamud

--- "KoKooYounhee<yoyounkoiuiucdeduwrote:

> Thanks very much. 
> It was exactly what I want.
> 
> >From next time, I will try to figure out more by myself.:-)
> Thanks again.
> 
> YoYounhee
> 
> ---- Original message ----
> >Date: Fri, 31 Dec 2004 15:54:11 -0500
> >From: "Roger D. PePeng<rprpenghjhsphdedu 
> >Subject: Re: [R] Export the R object  
> >To: "KoKooYounhee<yoyounkoiuiucdedu
> >Cc: R-help at stat.math.etethzh
> >
> >If you want to export data frame, you can use write.table() 
> to write out a CSCSV
> >(comma separated value) file, which you can then read into 
> Excel.
> >
> >-roger
> >
> >KoKooYounheerote:
> >> Hi, 
> >> 
> >> I just have a quick question.
> >> If I got some result as the result of R, how can I export 
> >> the result object?
> >> 
> >> I mean, if I want to use the result object in Excel or 
> other 
> >> program in order to more specific investigation, how can 
> I 
> >> export it?
> >> 
> >> If I just list the result and copy, 
> >> The result is like this..
> >> 
> >> 
> >> [586] "BB170029A10B06" "BB170029A20E06"
> >> 
> >> First column, automatically show the number of result and 
> >> other result also include the "".
> >> 
> >> If I want to use this result, I have to manipulate the 
> >> result by myself(I mean e.g remove " and remove [586] 
> like 
> >> this way)?????
> >> 
> >> Or there is any good way to export this result object to 
> >> other program?
> >> 
> >> Please help me. 
> >> 
> >> Thanks in advance.
> >> ========================
> >> YoYounheeoKooyounkoiuiucdedu
> >> 
> >> hthttp/cocomeduokoreac.krkrununygo> >> contact : 217-417-4868
> >> Graduate Student in Dept. of Computer Science
> >> University of Illinois at Urbana-Champaign
> >> 
> >> ______________________________________________
> >> R-help at stat.math.etethzh mailing list
> >> hthttps/stat.etethzh/mailman/lilistinfo-help
> >> PLEASE do read the posting guide! hthttp/wwwww-
> project.ororgosting-guide.hthtml> >> 
> ========================
> YoYounheeoKooyounkoiuiucdedu
> 
> hthttp/cocomeduokoreac.krkrununygo> contact : 217-417-4868
> Graduate Student in Dept. of Computer Science
> University of Illinois at Urbana-Champaign
> 
> ______________________________________________
> R-help at stat.math.etethzh mailing list
> hthttps/stat.etethzh/mailman/lilistinfo-help
> PLEASE do read the posting guide! hthttp/wwwww-project.ororgosting-guide.hthtml>




More information about the R-help mailing list