Safe Haskell | None |
---|
Conversions between R's RDS/RDA format and haskell data types.
tested with R 3.0.1
Missing:
- Data.Map
- better error reporting when the format is bad?
- more tests
- toRDA :: (RecordValues r, ToRDS (RDA (RecordValuesR r))) => Record r -> ByteString
- fromRDA :: forall __ r. FromRDA __ r => ByteString -> Record r
- class ToRDS a where
- class FromRDS a where
- type FromRDA a r = (HMap1 FLVPair a r, FromRDS (RDA a))
- type ToRDSRecord __ ___ xs = (RDSHLIST __ ___, ToRDS (LST ___), RecordValues xs, HList ___ ~ (HList (RecordValuesR xs) `HAppendR` HList `[ListStart, LVPair "names" [String]]`), RecordLabelsString (RecordLabels xs), HAppend (HList (RecordValuesR xs)) (HList `[ListStart, LVPair "names" [String]]`))
- type RDSHLIST xs' xs = (HNat2Integral (HLength xs), HFoldr (HSeq FToRDS) Put xs Put)
- data RDA a
- class Ix i => IxSize i where
- ixSize :: (i, i) -> [Int32]
- fromIxSize :: [Int32] -> (i, i)
- module Data.HList.CommonMain
functions to serialize many variables
A typical type would be
Record '[LVPair l1 (LVPair m1 x), LVPair l2 (LVPair m2 x)]
The outer labels (l1
, l2
) are the haskell-side. The inner labels
are the m1
m2
which are the names of the variables on the R side.
toRDA :: (RecordValues r, ToRDS (RDA (RecordValuesR r))) => Record r -> ByteStringSource
fromRDA :: forall __ r. FromRDA __ r => ByteString -> Record rSource
serializing a single variable
same as Binary but should be compatible with R's saveRDS
binary mode, which is for single objects
ToRDS Double | |
ToRDS Int32 | |
ToRDS String | abc => |
ToRDS Text | T.pack abc => |
ToRDS [Double] | |
ToRDS [Int32] | |
ToRDS [String] |
|
ToRDSRecord k __ ___ xs => ToRDS (Record xs) |
The type variables with underscores should be hidden |
ToRDS (Vector Double) | becomes a numeric vector |
ToRDS (Vector Int32) | integer vector |
ToRDS (Vector Text) | character vector |
(ToRDS t, ToRDS (RDA rs), ShowLabel k l2) => ToRDS (RDA (: * (LVPair k l2 t) rs)) | internal |
ToRDS (RDA ([] *)) | internal |
IxSize i => ToRDS (Array i Int32) | |
IxSize i => ToRDS (Array i Double) |
|
(ToRDS t, ShowLabel k l) => ToRDS (LVPair k l t) | probably internal |
(Source r Int32, Shape sh) => ToRDS (Array r sh Int32) | repa |
(Source r Double, Shape sh) => ToRDS (Array r sh Double) | repa |
FromRDS Double | |
FromRDS Int32 | |
FromRDS String | |
FromRDS Text | |
FromRDS [Double] | |
FromRDS [Int32] | |
FromRDS [String] | |
FromRDSRec a b as' as'2 bs' => FromRDS (Record bs') | |
FromRDS (Vector Double) | |
FromRDS (Vector Int32) | |
FromRDS (Vector Text) | |
(FromRDS t, FromRDS (RDA rs), ShowLabel k l2) => FromRDS (RDA (: * (LVPair k l2 t) rs)) | internal |
FromRDS (RDA ([] *)) | internal |
IxSize i => FromRDS (Array i Int32) | note indices become 0-based (see |
IxSize i => FromRDS (Array i Double) | note indices become 0-based (see |
(FromRDS t, ShowLabel k l) => FromRDS (LVPair k l t) | probably internal |
Shape sh => FromRDS (Array U sh Int32) | repa |
Shape sh => FromRDS (Array U sh Double) | repa |
types / internal
type ToRDSRecord __ ___ xs = (RDSHLIST __ ___, ToRDS (LST ___), RecordValues xs, HList ___ ~ (HList (RecordValuesR xs) `HAppendR` HList `[ListStart, LVPair "names" [String]]`), RecordLabelsString (RecordLabels xs), HAppend (HList (RecordValuesR xs)) (HList `[ListStart, LVPair "names" [String]]`))Source
labels are stored with the variables here. compare with the instance for Record
/ LST
which collects
the labels and saves them as an attribute called "names"
class Ix i => IxSize i whereSource
given bounds
of an array, produce a list of how many elements
are in each dimension. For example, a 3x2 array produces [3,2].
A single instance for "linear" indices would look like:
instance (A.Ix i, Num i) => IxSize i where ixSize x = [fromIntegral (A.rangeSize x)] fromIxSize [n] = (0, n-1)
But to avoid overlapping instances all monomorphic index types likely
to be used are just repeated here. fromIxSize produces 0-based indexes
for instances of Num
(Word
, Int
, Integer
), while minBound
is
used for other types.
R supports a dimnames attribute. This could be used but it is not so far.
IxSize Bool | |
IxSize Char | |
IxSize Int | |
IxSize Int8 | |
IxSize Int16 | |
IxSize Int32 | |
IxSize Int64 | |
IxSize Integer | |
IxSize Ordering | |
IxSize Word | |
IxSize Word8 | |
IxSize Word16 | |
IxSize Word32 | |
IxSize Word64 | |
IxSize () | |
(IxSize a, IxSize b) => IxSize (a, b) | |
(IxSize a, IxSize b, IxSize c) => IxSize (a, b, c) | |
(IxSize a, IxSize b, IxSize c, IxSize d) => IxSize (a, b, c, d) | |
(IxSize a, IxSize b, IxSize c, IxSize d, IxSize e) => IxSize (a, b, c, d, e) |
module Data.HList.CommonMain