Please allow me an unusual question. Is there any way that R can be closely integrated with a Microsoft Powerpoint presentation? I would like to embed R calculations in Powerpoint so that I will start Powerpoint, be prompted to enter some parameters, and an R function will run and return values and graphs. Thanks, John R 2.1.1 windows 2k John Sorkin M.D., Ph.D. Chief, Biostatistics and Informatics Baltimore VA Medical Center GRECC and University of Maryland School of Medicine Claude Pepper OAIC 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 410-605-7119 - NOTE NEW EMAIL ADDRESS: jsorkin@grecc.umaryland.edu [[alternative HTML version deleted]]
On Fri, 1 Jul 2005, John Sorkin wrote:> Please allow me an unusual question. > > Is there any way that R can be closely integrated with a Microsoft > Powerpoint presentation? I would like to embed R calculations in > Powerpoint so that I will start Powerpoint, be prompted to enter some > parameters, and an R function will run and return values and graphs.R can be driven by COM, so if Powerpoint supports COM (possibly via VBA) this would be possible. It is likely, as other MS Office applications do. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
khobson@fd9ns01.okladot.state.ok.us
2005-Jul-01 14:40 UTC
[R] R integration with Microsoft Powerpoint
Sure. Just run R in a BAT file. You just reference the BAT file in PowerPoint like any other EXE application via an OLE link. Of course you can always use VBA code in Powerpoint to Shell() to the BAT program. In R, type ?BATCH to see how the BAT file's content line should be coded to run the R program. mailto:khobson at odot.org Kenneth Ray Hobson, P.E. Oklahoma DOT - QA & IAS Manager 200 N.E. 21st Street Oklahoma City, OK 73105-3204 (405) 522-4985, (405) 522-0552 fax Visit our website at: http://www.okladot.state.ok.us/materials/materials.htm
khobson@fd9ns01.okladot.state.ok.us
2005-Jul-01 18:27 UTC
[R] R integration with Microsoft Powerpoint
Of course there are many ways to do it. The user input could come from R dialogs via the tcltk package or the Input() dialogs from VBA in Powerpoint. I chose the output as PDF. The R source code called cars.r, might go something like: pdf(file=paste(getwd(), "/", "cars.pdf", sep=""), width = 8.5, height = 11, onefile = TRUE, family = "Helvetica", title = "R Graphics Output", fonts = NULL, version = "1.1") plot(cars) lines(lowess(cars)) graphics.off() shell(paste(getwd(), "/", "cars.pdf", sep=""),wait=FALSE) #veiw PDF stop("all done") The cars.bat file, might go something like: "C:\Program Files\R\rw2010\bin\R.exe" CMD BATCH c:\myfiles\r\cars.r #Change the drives and paths to R.exe and the cars.r files. The cars.bat file was played from PowerPoint by creating the object and doubleclicking in the slideshow. The are other ways to do it of course. In PowerPoint, click the menu item Insert | Object | Create and browse to and select the cars.r file. I set the object as an icon and used the R.exe icon. VBA scripting to play the cars.bat file is not all that involved either. _______ mailto:khobson at odot.org Kenneth Ray Hobson, P.E. Oklahoma DOT - QA & IAS Manager 200 N.E. 21st Street Oklahoma City, OK 73105-3204 (405) 522-4985, (405) 522-0552 fax Visit our website at: http://www.okladot.state.ok.us/materials/materials.htm
khobson@fd9ns01.okladot.state.ok.us
2005-Jul-01 19:11 UTC
[R] R integration with Microsoft Powerpoint
>...snip...In PowerPoint, click the menu item Insert | Object | Create andbrowse to and select the cars.r file. ...snip... In the previous post snippet above, replace cars.r with cars.bat. To run the cars.bat program via VBA, I would typically insert a button. To do so in PowerPoint, right click the toolbar, select Control Toolbar and then click the button icon. Right click and drag and draw the button onto the slide. Double click the button object and add code something like: Private Sub CommandButton1_Click() Shell ("c:\myfiles\r\cars.bat") End Sub When passing input to a program like R, I typically use VBA's Input() and write the results to a TXT file. This is then easily read into R. mailto:khobson at odot.org Kenneth Ray Hobson, P.E. Oklahoma DOT - QA & IAS Manager 200 N.E. 21st Street Oklahoma City, OK 73105-3204 (405) 522-4985, (405) 522-0552 fax Visit our website at: http://www.okladot.state.ok.us/materials/materials.htm