ihaskell-inline-r (empty) → 0.1.0.0
raw patch · 3 files changed
+77/−0 lines, 3 filesdep +basedep +base64-bytestringdep +blaze-htmlsetup-changed
Dependencies added: base, base64-bytestring, blaze-html, bytestring, filepath, ihaskell, ihaskell-blaze, inline-r, template-haskell, temporary
Files
- Setup.hs +2/−0
- ihaskell-inline-r.cabal +27/−0
- src/IHaskell/Display/InlineR.hs +48/−0
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ ihaskell-inline-r.cabal view
@@ -0,0 +1,27 @@+name: ihaskell-inline-r+version: 0.1.0.0+synopsis: Embed R quasiquotes and plots in IHaskell notebooks.+homepage: https://tweag.github.io/HaskellR/+license: BSD3+author: Mathieu Boespflug, Alexander Vershilov+maintainer: Alexander Vershilov <alexander.vershilov@tweag.io>+copyright: Copyright (c) 2015, Tweag I/O Limited.+category: Development+build-type: Simple+cabal-version: >=1.10++library+ exposed-modules: IHaskell.Display.InlineR+ build-depends: base >=4.7 && <5+ ,inline-r >= 0.6.0.1+ ,ihaskell+ ,ihaskell-blaze+ ,filepath+ ,blaze-html+ ,bytestring+ ,base64-bytestring+ ,template-haskell+ ,temporary >= 1.2+ hs-source-dirs: src+ default-language: Haskell2010+ ghc-options: -Wall
+ src/IHaskell/Display/InlineR.hs view
@@ -0,0 +1,48 @@+-- |+-- Copyright: 2015 (C) Tweag I/O Limited++{-# LANGUAGE QuasiQuotes #-}+{-# LANGUAGE TemplateHaskell #-}+{-# OPTIONS_GHC -fno-warn-missing-fields #-}+module IHaskell.Display.InlineR+ ( r+ , rprint+ , rgraph+ , Language.R.Instance.runRegion+ ) where++import Control.Applicative+import Control.Monad (when)+import qualified Data.ByteString as BS+import qualified Data.ByteString.Base64 as Base64+import qualified Data.ByteString.Char8 as Char+import Data.Monoid+import H.Prelude.Interactive as H -- we use provide instances to IO Monad+import IHaskell.Display+import IHaskell.Display.Blaze () -- to confirm it's installed+import Language.Haskell.TH.Quote+import Language.R.Instance+import Language.R.QQ+import System.IO (hClose)+import System.IO.Temp (withSystemTempFile)+import qualified Text.Blaze.Html5 as BH+import qualified Text.Blaze.Html5.Attributes as BH++rprint :: QuasiQuoter+rprint = QuasiQuoter { quoteExp = \s -> [| do H.p $(quoteExp r s) |] }++rgraph :: QuasiQuoter+rgraph = QuasiQuoter { quoteExp = \s ->+ [| withSystemTempFile "ihaskell-inline-r-.png" $ \path h -> do+ hClose h+ _ <- [r| png(filename=path_hs, width=480, height=480, bg="white"); |]+ H.p $(quoteExp r s)+ _ <- [r| dev.off() |]+ encoded <- Base64.encode <$> BS.readFile path+ when (BS.null encoded) $+ fail "No graphical output."+ display $+ BH.img BH.!+ BH.src (BH.unsafeByteStringValue+ (Char.pack "data:image/png;base64," <> encoded))+ |] }