Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow NAs to be represented as Option types at the F# boundary #42

Open
kevinykuo opened this issue Oct 4, 2013 · 3 comments
Open

Allow NAs to be represented as Option types at the F# boundary #42

kevinykuo opened this issue Oct 4, 2013 · 3 comments
Labels
Type: Enhancement New feature or request

Comments

@kevinykuo
Copy link

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?

@hmansell
Copy link
Contributor

hmansell commented Oct 4, 2013

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 would get converted into a numeric vector, where the None values are NA), or perhaps using Nullable?

Do you think that would work for you?

@kevinykuo
Copy link
Author

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...

@tpetricek
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants