Hello All, We would like to call quantile() function from the R-package STATS in a Delphi program. If this is possible, could anyone provide us with an example? Thanks in advance. --Anna ----------------------------------------- Anna Belova Abt Associates Inc. 4800 Montgomery Ln, St 600 Bethesda, MD-20814 phone: 301-347-5304 fax: 301-652-7530 http://www.abtassociates.com/environment ----------------------------------------- This message may contain privileged and confidential informa...{{dropped}}
On 12/4/2006 2:27 PM, Anna Belova wrote:> Hello All, > > We would like to call quantile() function from the R-package STATS in a > Delphi program. If this is possible, could anyone provide us with an > example?You probably want to be talking to the Rcom-l list, see <http://mailman.csd.univie.ac.at/mailman/listinfo/rcom-l>. Duncan Murdoch
If your only interest is the quantile function, you may consider implementing your own version in Pascal. Since R is open source you can look at the source code here: https://svn.r-project.org/R/trunk/src/library/stats/R/quantile.R And use the code as a guideline (I recommend reading the GNU license before you use R for your own applications) You can alway use the COM capabilities in R, available at http://sunsite.univie.ac.at/rcom/ Try RSiteSearch("Delphi") for a few interesting threads on the subject. Regards, Francisco Dr. Francisco J. Zagmutt College of Veterinary Medicine and Biomedical Sciences Colorado State University Anna Belova wrote:> Hello All, > > We would like to call quantile() function from the R-package STATS in a > Delphi program. If this is possible, could anyone provide us with an > example? > > Thanks in advance. > > --Anna > ----------------------------------------- > Anna Belova > Abt Associates Inc. > 4800 Montgomery Ln, St 600 > Bethesda, MD-20814 > phone: 301-347-5304 > fax: 301-652-7530 > http://www.abtassociates.com/environment > > ----------------------------------------- > This message may contain privileged and confidential informa...{{dropped}} > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
Anna Belova wrote:> Hello All, > > We would like to call quantile() function from the R-package STATS in a > Delphi program. If this is possible, could anyone provide us with an > example?Hi Anna There was a translation of the header files from C to Delphi, so that you could used R directly without using DCom - Hans-Peter Suter translated / made them. I'll mail you the version which he send me off list. Rainer> > Thanks in advance. > > --Anna > ----------------------------------------- > Anna Belova > Abt Associates Inc. > 4800 Montgomery Ln, St 600 > Bethesda, MD-20814 > phone: 301-347-5304 > fax: 301-652-7530 > http://www.abtassociates.com/environment > > ----------------------------------------- > This message may contain privileged and confidential informa...{{dropped}} > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT) Department of Conservation Ecology and Entomology University of Stellenbosch Matieland 7602 South Africa Tel: +27 - (0)72 808 2975 (w) Fax: +27 - (0)86 516 2782 Fax: +27 - (0)21 808 3304 (w) Cell: +27 - (0)83 9479 042 email: RKrug at sun.ac.za Rainer at krugs.de
2006/12/5, Rainer M Krug <RKrug at sun.ac.za>:> There was a translation of the header files from C to Delphi, so that > you could used R directly without using DCom - Hans-Peter Suter > translated / made them.Thanks for mentioning. You can download these files any time from: - http://treetron.googlepages.com/ (select delphi interface units) BUT notice, that they will only enable you to write *packages* which contain Delphi code and not to link/embed R directly from Delphi. IMO you should use RCom as mentioned above. -- Regards, Hans-Peter
Anna Belova wrote:> Hello All, > > We would like to call quantile() function from the R-package STATS in a > Delphi program. If this is possible, could anyone provide us with an > example?It is possible, and in principle simple. The essentials: (1) Write a file containing the something like a script in R with whatever commands. (2) Start a process involving the execution of R with a command line containing two arguments, the name of the command file and the file where you want the output (results) to be. (3) wait for the process to stop. So, here is a function (returns true if everyhing worked OK) that does that: function StartRAndWait (CommandLine : string) : Boolean; var Proc_info: TProcessInformation; Startinfo: TStartupInfo; ExitCode: longword; CreateOK : Boolean; begin Result := False; { Initialize the structures } FillChar(proc_info, sizeof (TProcessInformation), #0); FillChar(startinfo, sizeof (TStartupInfo), #0); Startinfo.cb := sizeof (TStartupInfo); Startinfo.dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES; Startinfo.wShowWindow := SW_HIDE; { Attempt to create the process. If successful wait for it to end} CreateOK := CreateProcess(Nil, PChar('R.exe ' + CommandLine), nil, nil,False, CREATE_NEW_PROCESS_GROUP+NORMAL_PRIORITY_CLASS, nil, nil, StartInfo, proc_info); if (CreateOK) then begin WaitForSingleObject (proc_info.hProcess, INFINITE); GetExitCodeProcess(proc_info.hProcess, ExitCode); Result := True end; CloseHandle(proc_info.hThread); CloseHandle(proc_info.hProcess); end; The argument for the procedure (CommandLine) is a string, created by a statement like: Command := 'CMD BATCH ' + CommandFileName + ' ' + TempFileName; where CommandFileName is the name of the file with the script, and TempFileName is the name of the text file containing the output. The procedure is fairly lowlevel, but it worked for me using Delphi 7. I do not remember how I managed to put this together (probably a mix of help from the R and Delphi lists), so please do not ask questions about the finer details. Tom +----------------------------------------------------------------+ | Tom Backer Johnsen, Psychometrics Unit, Faculty of Psychology | | University of Bergen, Christies gt. 12, N-5015 Bergen, NORWAY | | Tel : +47-5558-9185 Fax : +47-5558-9879 | | Email : backer at psych.uib.no URL : http://www.galton.uib.no/ | +----------------------------------------------------------------+
Anna Belova wrote:> Hellp Tom, > > Thank you so much! > > Several people have helped by pointing us to using R as a COM server. This > is an exciting functionality, but unfortunately we are afraid we can't use > it in this project. > > I really appreciate your thought and your time.The solution I suggested was not using R as a COM server, but calling R directly in a thread. If you are using Delphi at all it should work. So, I consider the suggestion to be good. Besides, considering where your mail originates (a corporation), you might consider that I deserve a fee. Do you want a bank account number? Now, that might be difficult, considering that US bank systems are quite primitive by European standards, but nevertheless ... Tom> > Regards, > Anna > ----------------------------------------- > Anna Belova > Abt Associates Inc. > 4800 Montgomery Ln, St 600 > Bethesda, MD-20814 > phone: 301-347-5304 > fax: 301-652-7530 > http://www.abtassociates.com/environment > > > > > Tom Backer > Johnsen > <backer at psych.uib To > .no> Anna Belova > <Anna_Belova at abtassoc.com> > 12/05/2006 12:36 cc > PM r-help at stat.math.ethz.ch > Subject > Re: [R] Calling R functions in > Delphi > > > > > > > > > > > Anna Belova wrote: >> Hello All, >> >> We would like to call quantile() function from the R-package STATS in a >> Delphi program. If this is possible, could anyone provide us with an >> example? > > It is possible, and in principle simple. The essentials: (1) Write a > file containing the something like a script in R with whatever > commands. (2) Start a process involving the execution of R with a > command line containing two arguments, the name of the command file > and the file where you want the output (results) to be. (3) wait for > the process to stop. So, here is a function (returns true if > everyhing worked OK) that does that: > > function StartRAndWait (CommandLine : string) : Boolean; > var > Proc_info: TProcessInformation; > Startinfo: TStartupInfo; > ExitCode: longword; > CreateOK : Boolean; > begin > Result := False; > > { Initialize the structures } > > FillChar(proc_info, sizeof (TProcessInformation), #0); > FillChar(startinfo, sizeof (TStartupInfo), #0); > Startinfo.cb := sizeof (TStartupInfo); > Startinfo.dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES; > Startinfo.wShowWindow := SW_HIDE; > > { Attempt to create the process. If successful wait for it to end} > > CreateOK := CreateProcess(Nil, PChar('R.exe ' + CommandLine), nil, > nil,False, CREATE_NEW_PROCESS_GROUP+NORMAL_PRIORITY_CLASS, nil, > nil, StartInfo, proc_info); > if (CreateOK) then begin > WaitForSingleObject (proc_info.hProcess, INFINITE); > GetExitCodeProcess(proc_info.hProcess, ExitCode); > Result := True > end; > CloseHandle(proc_info.hThread); > CloseHandle(proc_info.hProcess); > end; > > The argument for the procedure (CommandLine) is a string, created by a > statement like: > > Command := 'CMD BATCH ' + CommandFileName + ' ' + TempFileName; > > where CommandFileName is the name of the file with the script, and > TempFileName is the name of the text file containing the output. The > procedure is fairly lowlevel, but it worked for me using Delphi 7. I > do not remember how I managed to put this together (probably a mix of > help from the R and Delphi lists), so please do not ask questions > about the finer details. > > Tom > > > +----------------------------------------------------------------+ > | Tom Backer Johnsen, Psychometrics Unit, Faculty of Psychology | > | University of Bergen, Christies gt. 12, N-5015 Bergen, NORWAY | > | Tel : +47-5558-9185 Fax : +47-5558-9879 | > | Email : backer at psych.uib.no URL : http://www.galton.uib.no/ | > +----------------------------------------------------------------+ > > > ----------------------------------------- > This message may contain privileged and confidential infor...{{dropped}}
R(D)COM available from CRAN (section Other) gives you R as a COM server. If Delphi can act as a COM client (which I think is true), you can access R directly from within your program without the need to write files.> Anna Belova wrote: >> Hello All, >> >> We would like to call quantile() function from the R-package STATS in a >> Delphi program. If this is possible, could anyone provide us with an >> example?-- Erich Neuwirth, University of Vienna Faculty of Computer Science Computer Supported Didactics Working Group Visit our SunSITE at http://sunsite.univie.ac.at Phone: +43-1-4277-39464 Fax: +43-1-4277-39459
Dear All, Thank you very much for all the insights! We truly appreciate your thought and your time. --Anna ----------------------------------------- Anna Belova Abt Associates Inc. 4800 Montgomery Ln, St 600 Bethesda, MD-20814 phone: 301-347-5304 http://www.abtassociates.com/environment ----------------------------------------- This message may contain privileged and confidential informa...{{dropped}}