Forum > General

How to connect to R languase

<< < (6/6)

I think following is most similar to what the OP wants.

Also there are a formal description on this issue.

In Windows, the key is calling R.dll from Lazarus app. Some explanations:

--- Quote ---The R DLL is mainly written in C and has _cdecl entry points. Calling it directly will be tricky except from C code (or C++ with a little care).

There is a version of the Unix-alike interface calling

int Rf_initEmbeddedR(int ac, char **av);
void Rf_endEmbeddedR(int fatal);

which is an entry point in R.dll. Examples of its use (and a suitable can be found in the tests/Embedding directory of the sources. You may need to ensure that R_HOME/bin is in your PATH so the R DLLs are found.

Examples of calling R.dll directly are provided in the directory src/gnuwin32/front-ends, including a simple command-line front end rtest.c whose code is

#define Win32
#include <windows.h>
#include <stdio.h>
#include <Rversion.h>
#define LibExtern __declspec(dllimport) extern
#include <Rembedded.h>
#include <R_ext/RStartup.h>
/* for askok and askyesnocancel */
#include <graphapp.h>

/* for signal-handling code */
#include <psignal.h>
--- End quote ---

I know little about C series. But It seems that there are some include files related with R, as can be seen in followings. 

#include <Rversion.h>
#define LibExtern __declspec(dllimport) extern
#include <Rembedded.h>
#include <R_ext/RStartup.h>

This C example should be convertible to Pascal with a "little" (ehm, converting those C headers to Pascal units) effort.


--- Quote from: ffilipelima on December 02, 2021, 03:57:20 pm ---is it necessary to declare any library?
could provide a file for this code?
I tried to replicate in Delphi but I failed. Do you know if its is possible to use the same code for Delphi?

--- End quote ---

No runcommand() is FPC only, though in theory you could port the "process" unit.


--- Quote from: Leledumbo on December 07, 2021, 09:43:30 am ---This C example should be convertible to Pascal with a "little" (ehm, converting those C headers to Pascal units) effort.

--- End quote ---

I think I've eyeballed the headers before and concluded that it was doable. However I lack the time or incentive to get directly involved (if somebody wanted this stuff and was prepared to offer a decent bounty it might change things).

Unfortunately I can't locate the earlier thread where I commented on this, since searching for " R " is tricky... a bit like finding a noodle in a hatrack.



[0] Message Index

[*] Previous page

Go to full version