From kry|ov@r00t @end|ng |rom gm@||@com  Wed Jun  8 16:57:54 2022
From: kry|ov@r00t @end|ng |rom gm@||@com (Ivan Krylov)
Date: Wed, 8 Jun 2022 17:57:54 +0300
Subject: [Rd] 
 Writing Extensions for R under Windows: is it better for GUIs
 to communicate with R via Rgui.exe, Rterm.exe or R.dll?
In-Reply-To: <emcfa70b95-004c-45fb-8936-55133f137688@dell>
References: <emcfa70b95-004c-45fb-8936-55133f137688@dell>
Message-ID: <20220608175754.5dbd228a@arachnoid>

On Sat, 04 Jun 2022 03:43:39 +0000
jcfaria <joseclaudio.faria at gmail.com> wrote:

> Writing Extensions for R under Windows: is it better for GUIs to 
> communicate with R via Rgui.exe, Rterm.exe or R.dll?

Well, WRE section 8 is all about linking the GUI to R as a DLL. It does
mention the alternative approaches like Rserve or DCOM, but such
interfaces are limited to some extents.

> In the construction of extensions (GUIs) for R, in the establishment
> of communication, according to the options below:
> 
> 1- Rgui.exe (via Windows API) vs. R.dll (embedded R)

Setting aside the fact that Windows API is not cross platform (which
may be not the point if you're writing a Windows-only GUI), the
messages that the application accepts and interprets are not a part of
a documented interface, so while they tend to be stable (because
Windows is mostly stable in handing the same kinds of messages to the
applications running there), they may be broken (like in R 4.2.0).

Linking to R.dll has a higher initial cost of setting up (you have to
write those callbacks, you have to set up R_HOME...), but the interface
won't be broken without a good reason and a migration plan.

> 2- Rterm.exe (via IPC) vs. R.dll (embedded R)

The console interface might be better understood and more stable than
passing messages to windows. If you're writing some kind of universal
interface suitable for different applications, all of which run a
Run-Eval-Print Loop in the command line, this may be a better approach
to take instead of linking to them individually. Although not without
problems [*], this is probably more stable than talking to Rgui.exe by
means of SendInput().

> What are the advantages and disadvantages in each case?

The advantages of linking to R.dll include being able to set up all
kinds of callbacks (EditFile, Busy, dataentry/dataviewer/selectlist) to
make their behaviour fit the theme of your application. The
disadvantages include a higher initial cost of setting it up and maybe
having to recompile it for different versions of R.

-- 
Best regards,
Ivan

[*] Check out ConEmu <https://conemu.github.io/> source code for
workarounds they probably amassed for all kinds of applications that
would otherwise prefer to be running in the standard console window.



[Rd] Writing Extensions for R under Windows: is it better for GUIs to communicate with R via Rgui.exe, Rterm.exe or R.dll?
Ivan Krylov