Recent

Author Topic: How to connect to R languase  (Read 16296 times)

bills

  • New Member
  • *
  • Posts: 44
How to connect to R languase
« on: April 07, 2018, 10:43:44 am »
How can i connect to R language? If this is come true, the R can be used to calculate Big data.I find that neither Rsession nor Rserve support lazarus...

Thank you.

Noodly

  • Jr. Member
  • **
  • Posts: 70
Re: How to connect to R languase
« Reply #1 on: April 07, 2018, 01:19:12 pm »
Windows 10 Home, Lazarus 2.02 (svn 60954), FPC 3.04

JD

  • Hero Member
  • *****
  • Posts: 1848
Re: How to connect to R languase
« Reply #2 on: April 07, 2018, 04:40:35 pm »
How can i connect to R language? If this is come true, the R can be used to calculate Big data.I find that neither Rsession nor Rserve support lazarus...

Thank you.

Sorry if you find this offensive BUT why don't you just use the R Studio. It was created for that purpose.

https://www.rstudio.com/

That is how I use R. Another alternative is to use Python, specifically rpy2.

JD
« Last Edit: April 07, 2018, 04:42:13 pm by JD »
Windows - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe),
Linux Mint - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe)

mORMot; Zeos 8; SQLite, PostgreSQL & MariaDB; VirtualTreeView

bills

  • New Member
  • *
  • Posts: 44
Re: How to connect to R languase
« Reply #3 on: April 08, 2018, 02:29:18 am »
How can i connect to R language? If this is come true, the R can be used to calculate Big data.I find that neither Rsession nor Rserve support lazarus...

Thank you.

Sorry if you find this offensive BUT why don't you just use the R Studio. It was created for that purpose.

https://www.rstudio.com/

That is how I use R. Another alternative is to use Python, specifically rpy2.

JD
Thank you JD. I am using R Studio. But i think if i can use R in my own program developed by lazarus, it will more powerful;

Thankyou very much.

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: How to connect to R languase
« Reply #4 on: April 08, 2018, 02:34:34 am »

Thank you JD. I am using R Studio. But i think if i can use R in my own program developed by lazarus, it will more powerful;

Are you looking to run R from within a Pascal program or run Pascal code (in a dynamic library) from R? Seems like both should be possible.


bills

  • New Member
  • *
  • Posts: 44
Re: How to connect to R languase
« Reply #5 on: April 08, 2018, 03:39:00 am »

Thank you JD. I am using R Studio. But i think if i can use R in my own program developed by lazarus, it will more powerful;

Are you looking to run R from within a Pascal program or run Pascal code (in a dynamic library) from R? Seems like both should be possible.

Thank you Phil . I want my Pascal program connect to R and post data and cmd to R, then the R calculate and show the result. I have tryed many method but all failed.
Thank you very much.

bigeno

  • Sr. Member
  • ****
  • Posts: 266
Re: How to connect to R languase
« Reply #6 on: April 08, 2018, 02:48:14 pm »
Thank you Phil . I want my Pascal program connect to R and post data and cmd to R, then the R calculate and show the result. I have tryed many method but all failed.
Thank you very much.
Did you try saving commands to script file, send script file to R and capture output ?

bills

  • New Member
  • *
  • Posts: 44
Re: How to connect to R languase
« Reply #7 on: April 09, 2018, 02:06:56 am »
Thank you Phil . I want my Pascal program connect to R and post data and cmd to R, then the R calculate and show the result. I have tryed many method but all failed.
Thank you very much.
Did you try saving commands to script file, send script file to R and capture output ?

I'll try this method.Thank U. But i think if I use script file, the efficiency may be low.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: How to connect to R languase
« Reply #8 on: April 09, 2018, 08:32:06 am »
Thank you Phil . I want my Pascal program connect to R and post data and cmd to R, then the R calculate and show the result. I have tryed many method but all failed.
Thank you very much.
Did you try saving commands to script file, send script file to R and capture output ?

I'll try this method.Thank U. But i think if I use script file, the efficiency may be low.
You are running an R library in both cases the efficiency is compromised by design.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

wp

  • Hero Member
  • *****
  • Posts: 11857
Re: How to connect to R languase
« Reply #9 on: April 09, 2018, 08:55:36 am »
You don't say anything about what you want to achieve with R. Maybe the built-in math and statistical functions in the units math and in FPC's numlib (http://wiki.lazarus.freepascal.org/NumLib_Documentation), or in external libraries such as DMath (https://sourceforge.net/projects/dmath/) can achieve what you need?

bills

  • New Member
  • *
  • Posts: 44
Re: How to connect to R languase
« Reply #10 on: April 09, 2018, 03:20:30 pm »
You don't say anything about what you want to achieve with R. Maybe the built-in math and statistical functions in the units math and in FPC's numlib (http://wiki.lazarus.freepascal.org/NumLib_Documentation), or in external libraries such as DMath (https://sourceforge.net/projects/dmath/) can achieve what you need?

The R can implement machine learning, but R's windows programing ability is poor. I have developed my own data processing program. I want to pass data to R by my program, and tell R to do  machine learning or other Statistical calculation, then the  R return results,such as data, Chart...

The c++, .net, java, php, python have their own api or class to connect to R, but it seems that lazarus has not.

Here is c++ example:http://finzi.psych.upenn.edu/R/library/RcppClassicExamples/html/RcppVector.html

sorry my English is poor.

bigeno

  • Sr. Member
  • ****
  • Posts: 266
Re: How to connect to R languase
« Reply #11 on: April 09, 2018, 05:25:12 pm »
The R can implement machine learning, but R's windows programing ability is poor. I have developed my own data processing program. I want to pass data to R by my program, and tell R to do  machine learning or other Statistical calculation, then the  R return results,such as data, Chart...

The c++, .net, java, php, python have their own api or class to connect to R, but it seems that lazarus has not.

Here is c++ example:http://finzi.psych.upenn.edu/R/library/RcppClassicExamples/html/RcppVector.html

sorry my English is poor.

there is DCOM server for R, I don't know if is still developed but you can try connect via com interface https://cran.r-project.org/contrib/extra/dcom/00ReadMe.html

bills

  • New Member
  • *
  • Posts: 44
Re: How to connect to R languase
« Reply #12 on: April 14, 2018, 05:27:12 pm »
I am sad that the Rserve only support java/C++/Python/.NET/CLI/C#/Ruby.

wp

  • Hero Member
  • *****
  • Posts: 11857
Re: How to connect to R languase
« Reply #13 on: April 14, 2018, 06:16:32 pm »
First of all: I don't know anything about R. But I guess that R can be controlled by a script of commands. In this case, your program would create the script and store it in a temporary file, call R (RScript?) in a separate process and pass the script file to it as a parameter. Finally your program would catch the output of R, parse it and extract the results.

Have a look at my "gnuplotter" which does the same with gnuplot: https://forum.lazarus.freepascal.org/index.php/topic,23839.msg253759.html#msg253759.

bills

  • New Member
  • *
  • Posts: 44
Re: How to connect to R languase
« Reply #14 on: April 15, 2018, 12:40:57 pm »
First of all: I don't know anything about R. But I guess that R can be controlled by a script of commands. In this case, your program would create the script and store it in a temporary file, call R (RScript?) in a separate process and pass the script file to it as a parameter. Finally your program would catch the output of R, parse it and extract the results.

Have a look at my "gnuplotter" which does the same with gnuplot: https://forum.lazarus.freepascal.org/index.php/topic,23839.msg253759.html#msg253759.

thank you wp.
My application uses the unit 'ShellCommandRunner', and click the button1 can get the correct result,but click the button2 i cant get the correct result.How can i do?
Quote
procedure TForm1.FormCreate(Sender: TObject);
begin
  th := TShellCommandRunnerThread.Create;
  th.OnOutputAvailable := @OnOutputAvailable;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  th.CommandLine := 'cmd /c dir c:\';
  th.Start;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  th.CommandLine :=  'cmd /c dir d:\';
  th.Start;
end;

// Capture the output
procedure TForm1.OnOutputAvailable(const pBuffer: PByteArray; const pCount: integer);
var
  s: string;
begin
  s := TShellCommandRunner.BufferToString(pBuffer, pCount);
  Memo1.Append(ConsoleToUTF8(s));
end; 

 

TinyPortal © 2005-2018