Rlang-QQ-0.1.0.3: quasiquoter for inline-R code

Safe HaskellNone

RlangQQ.Binary

Contents

Description

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

Synopsis

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.

fromRDA :: forall __ r. FromRDA __ r => ByteString -> Record rSource

serializing a single variable

class ToRDS a whereSource

same as Binary but should be compatible with R's saveRDS binary mode, which is for single objects

Methods

toRDS :: a -> PutSource

Instances

ToRDS Double 
ToRDS Int32 
ToRDS String

abc => c('ab')

ToRDS Text

T.pack abc => c('ab')

ToRDS [Double] 
ToRDS [Int32] 
ToRDS [String]

["abc","def"] => c('abc','def')

ToRDSRecord k __ ___ xs => ToRDS (Record xs)

lab .=. val .*. emptyRecord => list(lab= (toRDS val) ).

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 c('ab','cd')

(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)

Data.Array.Array become arrays in R

(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

class FromRDS a whereSource

Methods

fromRDS :: Get aSource

Instances

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)

IxSize i => FromRDS (Array i Double)

note indices become 0-based (see IxSize)

(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 FromRDA a r = (HMap1 FLVPair a r, FromRDS (RDA a))Source

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

type RDSHLIST xs' xs = (HNat2Integral (HLength xs), HFoldr (HSeq FToRDS) Put xs Put)Source

data RDA a 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"

Instances

(FromRDS t, FromRDS (RDA rs), ShowLabel k l2) => FromRDS (RDA (: * (LVPair k l2 t) rs))

internal

FromRDS (RDA ([] *))

internal

(ToRDS t, ToRDS (RDA rs), ShowLabel k l2) => ToRDS (RDA (: * (LVPair k l2 t) rs))

internal

ToRDS (RDA ([] *))

internal

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.

Methods

ixSize :: (i, i) -> [Int32]Source

fromIxSizeSource

Arguments

:: [Int32] 
-> (i, i)

with 0-based indexes

Instances