[R] Running an R script from Delphi 7

Tom Backer Johnsen backer at psych.uib.no
Tue Apr 7 19:46:55 CEST 2009


After some headscratching I found the solution.  Perhaps the options for 
calling R has been changed.  Place " CMD BATCH --no-save --silent " 
between the call on R and the naming of the files for input and output.

Tom

Tom Backer Johnsen wrote:
> Gentlepersons:
> 
> A long time ago I used to be able to start R (version 2.6.1) from a 
> Delphi 7 program and run a script by using a procedure like the following:
> 
> 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, nil, nil, nil, nil,
>    CreateOK := CreateProcess(Nil, PChar('C:\Program 
> Files\R\R-2.8.1\bin\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;
> 
> Now it seems to hang on the call on WaitForSingleObject toward the end. 
>  My current version of R is 2.8.1 if that is relevant.  Does anybody 
> have any suggestions?
> 
> Tom
> 
> ______________________________________________
> R-help at r-project.org 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.


-- 
+----------------------------------------------------------------+
| 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/ |
+----------------------------------------------------------------+




More information about the R-help mailing list