konne / RserveCLI2

A fork of RServeCLI
Other
30 stars 21 forks source link

The factor integers are not recognized #29

Closed abelykh0 closed 3 years ago

abelykh0 commented 9 years ago

Use datasets::HairEyeColor

You will receive bunches of ints instead of strings. This is my proposed fix: in Qap1.cs, line 744 replace with this:

            case XtArrayInt:
                {
                    var res = new int[length / 4];
                    var intBuf = new byte[4];
                    for (long i = 0; i < length; i += 4)
                    {
                        Array.Copy(data, start + i, intBuf, 0, 4);
                        res[i / 4] = BitConverter.ToInt32(intBuf, 0);
                    }

                    result = null;
                    string[] classAttribute;
                    if (attrs != null
                        && attrs.ContainsKey("class"))
                    {
                        classAttribute = attrs["class"].AsStrings;
                        if (classAttribute.Contains("Date"))
                        {
                            // Treat as dates
                            result = new SexpArrayDate(res);
                        }

                        // Treat as strings
                        if (attrs.ContainsKey("class"))
                        {
                            string[] levels = attrs["levels"].AsStrings;
                            result = new SexpArrayString();
                            foreach (int levelIndex in res)
                            {
                                result.Add(levels[levelIndex - 1]);
                            }
                        }
                    }

                    if (result == null)
                    {
                        result = new SexpArrayInt(res);
                    }
                }
                break;
SurajGupta commented 9 years ago

sorry I"m just getting to this. Will look into it soon.