Rlang-QQ- quasiquoter for inline-R code

Safe HaskellNone




A quasiquoter to help with calling R (http://www.r-project.org/) from ghc.


the quasiquoter

r :: QuasiQuoterSource

Calls R with the supplied string. Variables in R prefixed hs_ cause the corresponding (un-prefixed) variable to be converted. The variable(s) must be in the class ToRVal.

For example, when this file http://code.haskell.org/~aavogt/examples/test.hs is run

 import RlangQQ

 x = [0 .. 10  :: Double]
 y = map (sin . (*pi) . (/10)) x

 main = do
     plot(qplot( hs_x, hs_y ))

The file is produced


R -> haskell

Currently nothing is done to the output. It should be possible to return the original hs_foo variables in an extensible record, (possibly limited to the case where they have been modified?).

ie.if there is a [r| hs_foo <- "abc" |], then at the very bottom of the generated R file we should have be calling an R function like serialize(hs_foo). then on the haskell side we have:

  return (label foo $ deserialize "hs_foo" `asTypeOf` hs_foo,
          label abc $ deserialize "hs_abc" `asTypeOf` hs_abc,
          ... )

Where the tuple is an extensible record, and the IO needed to get the result is also sequenced.

Variables whose first occurence is an assignment do not need a corresponding variable to be sent into R:

 [r| hs_x <- rnorm(5); hs_x <- sum(hs_x) |]
better IPC

perhaps communicating through files is not the best idea. When there are multiple quasi quotes, maybe they should be connecting to the same session.

Marshalling other types (Vector, Array, Map etc.).

Use FromRVal