Skip to content

List of NAs is returned as SexpArrayBool instead of SexpArrayDouble #31

@hebu

Description

@hebu

I faced this issue today: I have an R algorithm that should return a list of doubles. Whenever it returns a list that does contain NAs only, it will be decoded as a SexpArrayBool and .AsDoubles will run into an NotSupportedException.

So, now I am doing this workaround:

public IList<double> GetDoublesVector(string symbolOrExpression)
    {
        try
        {
            return _rConnection.Eval(symbolOrExpression).AsDoubles.ToList();
        }
        catch (NotSupportedException e)
        {
            return ((ICollection<Sexp>) _rConnection.Eval(symbolOrExpression).Values).Select<Sexp, double>(s =>
            {
                if (s.IsNa)
                {
                    return Double.NaN;
                }
                else
                {
                    return s.AsDouble;
                }
            }).ToList();
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions