RProvider
RProvider copied to clipboard
Allow NAs to be represented as Option types at the F# boundary
I'm currently passing .NET NaN's to R via RDotNet (without RProvider) then convert them to NA's using a series of RDotNet engine.evaluate statements.
This isn't exactly elegant, so what I'd like to do is streamline the process by taking advantage of RProvider's syntax, e.g.
define a function
let nan2na (arr: RDotNet.SymbolicExpression) =
engine.SetSymbol("arr",arr)
engine.Evaluate("arr[is.nan(arr)] <- NA") |> ignore
engine.GetSymbol("arr")
// then we can do the following
let result = data |> R.data_matrix |> nan2na |> R.fancystuff_etc
However, when I try to do this I get a bunch of nulls back... along with A first chance exception of type 'System.ArgumentException' occurred in RDotNet.dll
What is the best way of dealing with this?
I'm a little bit unclear what you are trying to achieve here. But I think in general we don't have good handling for NA in the RProvider. Seems like NaNs are working correctly, but probably NAs are not.
If you have to resort to using evaluate (or anything on the R engine) then we have probably failed. Rather, we should have a way of representing NA on the F# side, so you can map your NaNs to NA on the F# side of things.
The natural way of doing this is probably using the Option type (so a sequence of Option
Do you think that would work for you?
Being able to "map to NA on the F# side of things" would be great, and I agree that using options makes sense.
I'm relatively new to F# (coming from R), but the alternatives I can think of are quite messy...
This probably depends on what R.NET provides (I think it always returns N.A. as Double.NaN
), but it would be good to investigate and provide some option.