Skip to content

R bridge replacement#271

Open
AndrewIOM wants to merge 38 commits intofslaborg:masterfrom
AndrewIOM:r-bridge-replacement
Open

R bridge replacement#271
AndrewIOM wants to merge 38 commits intofslaborg:masterfrom
AndrewIOM:r-bridge-replacement

Conversation

@AndrewIOM
Copy link
Copy Markdown
Collaborator

@AndrewIOM AndrewIOM commented Apr 8, 2026

Proposed Changes

R.NET is not maintained and is a complex codebase including substantial overhead that is not required by RProvider. This draft PR utilises a far smaller, F# R interop layer (RBridge), which only implements the raw interop and structural elements required by RProvider. See #270

Types of changes

What types of changes does your code introduce to RProvider?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • Build and tests pass locally
  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have added necessary documentation (if appropriate)

Further comments

In this PR, I have replaced R.NET entirely. In removing R.NET and replacing with the smaller bridge layer, I have made a clearer distinction between the raw native R C API and structural elements of the R language (which sit in RBridge and RBridge.Extensions), and placed a newer semantic layer into RProvider itself. This means RProvider has full control over its form, operator overrides etc.

For the bridging layer, I have mostly been following the latest embedded R docs rather than referring to R.NET, which should help us to clear up some of the very old bugs.

Key changes

Minimum (tested) supported versions

Moves minimum versions to R v4.5.0 and .NET 8. However, the type provider may work with older versions of R but these are not fully tested. (R exports different bindings between versions and between platforms, and since 4.5 are working to establish a modern public C API).

Type provider SDK

Uses the latest SDK and moves to the latest nuget packaging format. To accomodate this, I refactored to remove the dependency that design-time used to have on the runtime.

NA support

The RBridge has NA support to and from R through the F# option type. I revised RProvider to use this layer. The structural converters to request values from R to .NET values (i.e. using _.FromR<'t>() and _.TryFromR<'t>()) do allow access directly to non-options (e.g. float[]), but if there are NA values in the data it will not return any value or throw. Addresses #179 .

Semantic types layer

There is now a new semantic types layer within RProvider, in the RTypes module. This includes scalars, vectors, data frames, and factors. The semantic types keep data in R memory and support mathematical operators where appropriate.

The type provider now has a new root erased type (RExpr) and from this you can access the semantic layer with .AsTyped, .TryAsTyped, and similarly .AsDataFrame, .AsList, etc. or .Try* versions also.

Plugin system

I have removed the old plugin system, as it no longer fit with current F# scripting practices, and was very brittle. Also, the Deedle plugin has been recently removed from Deedle, which was the main plugin that existed. Now, the approach should be to explicitly convert from types in the semantic layer (i.e. R DataFrame -> Deedle).

Dependencies

By slimming the R<->.NET conversion system and the bridge layer, most dependencies have been removed.

Testing

The test project is now using Expecto, and consumes a locally-built nuget package specifically built for the purposes of running tests. The required nuget is built in the FAKE build script. All tests pass.

Status

All tests pass. Documentation is now very out of date and requires an overhaul. I suggest that this can continue in subsequent PRs.

All building and testing and packing works fine locally on macos. However, I cannot get the github runner to do the same. The runner is for some reason not packing the typeprovider folder within the nuget package; it seems to not be seeing the type provider SDK targets.

I have yet to test the provider on windows. Any issues will arise from R initialisation within RBridge, where changes will need to be made.

Smaller changes made as part of conversion process

  • bindingInfo in R interop switched to use SEXP types rather than R typeof(get(..)) execution.
  • getBindings and other core API functions actually now properly use R environments / namespaces; this was not implemented before (in RInterop).
  • Refactored 'call' within Runtime to use the namespace of the package to retrieve the symbol for the required function, then call it directly. Drops support for tuple-based named arguments.

AndrewIOM added 30 commits April 1, 2026 09:59
- Removed old interception loggers; now defaults to file-based logging.
@AndrewIOM AndrewIOM marked this pull request as ready for review April 28, 2026 12:05
@AndrewIOM
Copy link
Copy Markdown
Collaborator Author

Running dotnet fsi build.fsx works fine locally on macos. However, the packing of the type provider files doesn't seem to work correctly in github runners, despite everything being equal from what I can tell. I have spent a long time trying to fix this but can't figure it out. The typeproviders folder isn't added to the nuget.

Here is a locally built nuget: RProvider.3.0.0-alpha1.nupkg.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant