{-# LANGUAGE DataKinds #-}
{-# Language ViewPatterns #-}
module Language.R.Internal
( r1
, r2
, installIO
) where
import Control.Memory.Region
import qualified Foreign.R as R
import Language.R
import Data.ByteString as B
import Foreign.C.String ( withCString )
inVoid :: R V z -> R V z
inVoid = id
{-# INLINE inVoid #-}
r1 :: ByteString -> SEXP s a -> IO (SomeSEXP V)
r1 fn a =
useAsCString fn $ \cfn -> R.install cfn >>= \f ->
R.withProtected (R.lang2 f (R.release a)) (unsafeRunRegion . inVoid . eval)
r2 :: ByteString -> SEXP s a -> SEXP s b -> IO (SomeSEXP V)
r2 fn a b =
useAsCString fn $ \cfn -> R.install cfn >>= \f ->
R.withProtected (R.lang3 f (R.release a) (R.release b)) (unsafeRunRegion . inVoid . eval)
installIO :: String -> IO (SEXP V 'R.Symbol)
installIO str = withCString str R.install