inline-r 1.0.0 → 1.0.1
raw patch · 6 files changed
+290/−195 lines, 6 filesdep ~basedep ~inline-cdep ~mtl
Dependency ranges changed: base, inline-c, mtl, primitive, singletons-th, strict, template-haskell, transformers, unix
Files
- CHANGELOG.md +6/−0
- inline-r.cabal +219/−192
- src/Language/R/Instance.hs +7/−1
- src/Language/R/QQ.hs +21/−2
- tests/test-env1.hs +17/−0
- tests/test-env2.hs +20/−0
CHANGELOG.md view
@@ -1,5 +1,11 @@ # Change Log +## 1.0.1 - 2023-05-22+* Populate `R_LIBS` environment variable when starting R (#393)+* Map backslashes to forwardslashes in temp file names under Windows (#399)+* Relax upper bounds for GHC 9.6+* Fix imports for compatibility with mtl-2.3 (#414)+ ## 1.0.0 - 2022-11-11 * Support for R >= 4.2. * Support for GHC 9 and GHC 9.2.
inline-r.cabal view
@@ -1,225 +1,252 @@-name: inline-r-version: 1.0.0-license: BSD3-license-file: LICENSE-copyright: Copyright (c) 2013-2015 Amgen, Inc.- Copyright (c) 2015-2020 Tweag I/O Limited.-author: Mathieu Boespflug, Facundo Dominguez, Alexander Vershilov-maintainer: Mathieu Boespflug <m@tweag.io>-build-type: Simple-Category: FFI-Synopsis: Seamlessly call R from Haskell and vice versa. No FFI required.+cabal-version: 2.2+name: inline-r+version: 1.0.1+license: BSD-3-Clause+license-file: LICENSE+author: Mathieu Boespflug, Facundo Dominguez, Alexander Vershilov+maintainer: Mathieu Boespflug <m@tweag.io>+build-type: Simple+Category: FFI+Synopsis: Seamlessly call R from Haskell and vice versa. No FFI required. description:- For up to date Haddock documentation, please see <http://www.stackage.org/package/inline-r>.--homepage: https://tweag.github.io/HaskellR-cabal-version: >=1.10+homepage: https://tweag.github.io/HaskellR -extra-source-files: CHANGELOG.md- cbits/missing_r.h- tests/shootout/binarytrees.R- tests/shootout/fasta.R- tests/shootout/knucleotide.R- tests/shootout/fastaredux.R- tests/shootout/mandelbrot.R- tests/shootout/mandelbrot-noout.R- tests/shootout/nbody.R- tests/shootout/pidigits.R- tests/shootout/regexdna.R- tests/shootout/reversecomplement.R- tests/shootout/spectralnorm.R- tests/shootout/spectralnorm-math.R- tests/shootout/fannkuchredux.R- tests/R/fib.R- tests/R/fib-benchmark.R- ./R/collectAntis.R-extra-tmp-files: inline-r.buildinfo+extra-source-files:+ CHANGELOG.md+ cbits/missing_r.h+ tests/shootout/binarytrees.R+ tests/shootout/fasta.R+ tests/shootout/knucleotide.R+ tests/shootout/fastaredux.R+ tests/shootout/mandelbrot.R+ tests/shootout/mandelbrot-noout.R+ tests/shootout/nbody.R+ tests/shootout/pidigits.R+ tests/shootout/regexdna.R+ tests/shootout/reversecomplement.R+ tests/shootout/spectralnorm.R+ tests/shootout/spectralnorm-math.R+ tests/shootout/fannkuchredux.R+ tests/R/fib.R+ tests/R/fib-benchmark.R+ ./R/collectAntis.R+extra-tmp-files: inline-r.buildinfo source-repository head- type: git+ type: git location: git://github.com/tweag/HaskellR.git subdir: inline-r library- exposed-modules: Control.Memory.Region- Data.Vector.SEXP- Data.Vector.SEXP.Base- Data.Vector.SEXP.Mutable- Foreign.R- Foreign.R.Constraints- Foreign.R.Context- Foreign.R.Embedded- Foreign.R.Encoding- Foreign.R.Error- Foreign.R.Internal- Foreign.R.Parse- Foreign.R.Type- H.Prelude- H.Prelude.Interactive- Language.R- Language.R.Debug- Language.R.GC- Language.R.Globals- Language.R.HExp- Language.R.Instance- Language.R.Internal- Language.R.Internal.FunWrappers- Language.R.Internal.FunWrappers.TH- Language.R.Literal- Language.R.Matcher- Language.R.QQ+ exposed-modules:+ Control.Memory.Region+ Data.Vector.SEXP+ Data.Vector.SEXP.Base+ Data.Vector.SEXP.Mutable+ Foreign.R+ Foreign.R.Constraints+ Foreign.R.Context+ Foreign.R.Embedded+ Foreign.R.Encoding+ Foreign.R.Error+ Foreign.R.Internal+ Foreign.R.Parse+ Foreign.R.Type+ H.Prelude+ H.Prelude.Interactive+ Language.R+ Language.R.Debug+ Language.R.GC+ Language.R.Globals+ Language.R.HExp+ Language.R.Instance+ Language.R.Internal+ Language.R.Internal.FunWrappers+ Language.R.Internal.FunWrappers.TH+ Language.R.Literal+ Language.R.Matcher+ Language.R.QQ if !os(windows)- exposed-modules: Foreign.R.EventLoop- Language.R.Event- other-modules: Control.Monad.R.Class- Control.Monad.R.Internal- Data.Vector.SEXP.Mutable.Internal- Internal.Error- build-depends: base >=4.7 && <5- , aeson >=0.6 && <2.2- , bytestring >=0.10 && <0.12- , containers >=0.5 && <0.7- , data-default-class >=0.1.2.0 && <0.2- , deepseq >=1.3 && <1.5- , exceptions >=0.6 && <1.1- , heredoc >=0.2 && <0.3- , mtl >=2.1 && <2.3- , pretty >=1.1 && <1.2- , primitive >=0.5 && <0.8- , process >=1.2 && <1.7- , reflection >=2 && <2.2- , setenv >=0.1.1 && <0.2- , template-haskell >=2.8 && <2.20- , temporary >=1.2 && <1.4- , text >=0.11 && <2.1- , th-lift >=0.6 && <0.9- , th-orphans >=0.8 && <0.14- , transformers >=0.3 && <0.6- , vector >=0.10 && <0.14- if impl(ghc < 8.2.1)+ exposed-modules:+ Foreign.R.EventLoop+ Language.R.Event+ other-modules:+ Control.Monad.R.Class+ Control.Monad.R.Internal+ Data.Vector.SEXP.Mutable.Internal+ Internal.Error+ build-depends:+ base >=4.7 && <5,+ aeson >=0.6 && <2.2,+ bytestring >=0.10 && <0.12,+ containers >=0.5 && <0.7,+ data-default-class >=0.1.2.0 && <0.2,+ deepseq >=1.3 && <1.5,+ exceptions >=0.6 && <1.1,+ heredoc >=0.2 && <0.3,+ inline-c >=0.6 && <0.10,+ mtl >=2.1 && <2.4,+ pretty >=1.1 && <1.2,+ primitive >=0.5 && <0.9,+ process >=1.2 && <1.7,+ reflection >=2 && <2.2,+ setenv >=0.1.1 && <0.2,+ template-haskell >=2.8 && <2.21,+ temporary >=1.2 && <1.4,+ text >=0.11 && <2.1,+ th-lift >=0.6 && <0.9,+ th-orphans >=0.8 && <0.14,+ transformers >=0.3 && <0.7,+ vector >=0.10 && <0.14,+ if impl(ghc <9) build-depends:- inline-c >=0.5.6.1 && <0.6+ singletons >=2.7 && <3, else build-depends:- inline-c >=0.6 && <0.10- if impl(ghc <9)- build-depends: singletons >=2.7 && <3- else- build-depends:- singletons >=3 && <3.1,- singletons-th >=3 && <3.2- hs-source-dirs: src- includes: cbits/missing_r.h- c-sources: cbits/missing_r.c- include-dirs: cbits- default-language: Haskell2010- other-extensions: CPP- ForeignFunctionInterface- build-tools: hsc2hs+ singletons >=3 && <3.1,+ singletons-th >=3 && <3.3,+ hs-source-dirs: src+ includes: cbits/missing_r.h+ c-sources: cbits/missing_r.c+ include-dirs: cbits+ default-language: Haskell2010+ other-extensions:+ CPP+ ForeignFunctionInterface if os(windows)- extra-libraries: R+ extra-libraries: R else- build-depends: unix >= 2.6 && <2.8+ build-depends: unix >= 2.6 && <2.9 pkgconfig-depends: libR >= 3.0 -- XXX -fcontext-stack=32 required on GHC >= 7.8 to allow foreign -- export function -wrappers of high arities.- ghc-options: -freduction-depth=32+ ghc-options: -freduction-depth=32 --- We don't use ticks for promoted constructors, because we use --- promoted constructors heavily and because they confuse hsc2hs.- ghc-options: -Wall -fno-warn-unticked-promoted-constructors+ ghc-options: -Wall -fno-warn-unticked-promoted-constructors test-suite tests- main-is: tests.hs- type: exitcode-stdio-1.0- build-depends: inline-r- , base >=4.6 && <5- , bytestring >=0.10 && <0.12- , directory >=1.2 && <1.4- , filepath >=1.3 && <1.5- , heredoc >=0.2 && <0.3- , ieee754 >=0.7 && <0.9- , mtl >=2.0 && <2.3- , process >=1.2 && <1.7- , quickcheck-assertions >=0.1.1 && <0.4- , singletons >=0.10 && <3.1- , strict >=0.3.2 && <0.5- , tasty >=0.11 && <1.5- , tasty-expected-failure >=0.11 && <0.13- , tasty-golden >=2.3 && <2.4- , tasty-hunit >=0.4.1 && <0.11- , tasty-quickcheck >=0.4.1 && <0.11- , temporary >=1.2 && <1.4- , text >=0.11 && <2.1- , vector >=0.12.3.1 && <0.14+ main-is: tests.hs+ type: exitcode-stdio-1.0+ build-depends:+ inline-r,+ base >=4.6 && <5,+ bytestring >=0.10 && <0.12,+ directory >=1.2 && <1.4,+ filepath >=1.3 && <1.5,+ heredoc >=0.2 && <0.3,+ ieee754 >=0.7 && <0.9,+ mtl >=2.0 && <2.4,+ process >=1.2 && <1.7,+ quickcheck-assertions >=0.1.1 && <0.4,+ singletons >=0.10 && <3.1,+ strict >=0.3.2 && <0.6,+ tasty >=0.11 && <1.5,+ tasty-expected-failure >=0.11 && <0.13,+ tasty-golden >=2.3 && <2.4,+ tasty-hunit >=0.4.1 && <0.11,+ tasty-quickcheck >=0.4.1 && <0.11,+ temporary >=1.2 && <1.4,+ text >=0.11 && <2.1,+ vector >=0.12.3.1 && <0.14, if !os(windows)- build-depends: unix >=2.5 && <2.8- other-modules: Test.GC- Test.FunPtr- Test.Constraints- Test.Event- Test.Regions- Test.Vector- Test.Matcher- ghc-options: -Wall -threaded- hs-source-dirs: tests- default-language: Haskell2010+ build-depends: unix >=2.5 && <2.9,+ other-modules:+ Test.GC+ Test.FunPtr+ Test.Constraints+ Test.Event+ Test.Regions+ Test.Vector+ Test.Matcher+ ghc-options: -Wall -threaded+ hs-source-dirs: tests+ default-language: Haskell2010 test-suite test-qq- main-is: test-qq.hs- type: exitcode-stdio-1.0- build-depends: inline-r- , base >=4.6 && <5- , mtl >=2.0 && <2.3- , process >=1.2 && <1.7- , tasty-hunit >=0.4.1 && <0.11- , singletons >=0.9 && <3.1- , text >=0.11 && <2.1- ghc-options: -Wall -threaded- hs-source-dirs: tests- default-language: Haskell2010+ main-is: test-qq.hs+ type: exitcode-stdio-1.0+ build-depends:+ inline-r,+ base >=4.6 && <5,+ mtl >=2.0 && <2.4,+ process >=1.2 && <1.7,+ tasty-hunit >=0.4.1 && <0.11,+ singletons >=0.9 && <3.1,+ text >=0.11 && <2.1,+ ghc-options: -Wall -threaded+ hs-source-dirs: tests+ default-language: Haskell2010 test-suite test-shootout- main-is: test-shootout.hs- type: exitcode-stdio-1.0- other-modules: Test.Scripts- build-depends: inline-r- , base >=4.6 && <5- , filepath >=1.3 && <1.5- , process >=1.2 && <1.7- , silently >=1.2 && <1.3- , tasty >=0.3 && <1.5- , tasty-hunit >=0.4.1 && <0.11- , template-haskell >=2.8 && <2.20- ghc-options: -Wall -threaded- hs-source-dirs: tests- default-language: Haskell2010+ main-is: test-shootout.hs+ type: exitcode-stdio-1.0+ other-modules: Test.Scripts+ build-depends:+ inline-r,+ base >=4.6 && <5,+ filepath >=1.3 && <1.5,+ process >=1.2 && <1.7,+ silently >=1.2 && <1.3,+ tasty >=0.3 && <1.5,+ tasty-hunit >=0.4.1 && <0.11,+ template-haskell >=2.8 && <2.21,+ ghc-options: -Wall -threaded+ hs-source-dirs: tests+ default-language: Haskell2010 if os(windows)- buildable: False+ buildable: False +test-suite test-env1+ main-is: test-env1.hs+ type: exitcode-stdio-1.0+ build-depends:+ inline-r,+ base >=4.6 && <5,+ tasty >=0.3 && <1.5,+ tasty-hunit >=0.4.1 && <0.11,+ ghc-options: -Wall -threaded+ hs-source-dirs: tests+ default-language: Haskell2010++test-suite test-env2+ main-is: test-env2.hs+ type: exitcode-stdio-1.0+ build-depends:+ inline-r,+ base >=4.6 && <5,+ tasty >=0.3 && <1.5,+ tasty-hunit >=0.4.1 && <0.11,+ ghc-options: -Wall -threaded+ hs-source-dirs: tests+ default-language: Haskell2010+ benchmark bench-qq- main-is: bench-qq.hs- type: exitcode-stdio-1.0- build-depends: inline-r- , base >=4.6 && <5- , criterion >=0.8 && <1.7- , filepath >=1.3 && <1.5- , process >=1.2 && <1.7- , template-haskell >=2.8 && <2.20- ghc-options: -Wall -threaded- hs-source-dirs: tests- default-language: Haskell2010+ main-is: bench-qq.hs+ type: exitcode-stdio-1.0+ build-depends:+ inline-r,+ base >=4.6 && <5,+ criterion >=0.8 && <1.7,+ filepath >=1.3 && <1.5,+ process >=1.2 && <1.7,+ template-haskell >=2.8 && <2.21,+ ghc-options: -Wall -threaded+ hs-source-dirs: tests+ default-language: Haskell2010 benchmark bench-hexp- main-is: bench-hexp.hs- type: exitcode-stdio-1.0- build-depends: inline-r- , base >=4.6 && <5- , criterion >=0.8 && <1.7- , primitive >=0.5 && <0.8- , vector >=0.10 && <0.14- , singletons >=2.7 && <3.1- ghc-options: -Wall -threaded- hs-source-dirs: tests- default-language: Haskell2010+ main-is: bench-hexp.hs+ type: exitcode-stdio-1.0+ build-depends:+ inline-r,+ base >=4.6 && <5,+ criterion >=0.8 && <1.7,+ primitive >=0.5 && <0.9,+ vector >=0.10 && <0.14,+ singletons >=2.7 && <3.1,+ ghc-options: -Wall -threaded+ hs-source-dirs: tests+ default-language: Haskell2010
src/Language/R/Instance.hs view
@@ -37,6 +37,7 @@ , finalize ) where +import Control.Monad ((<=<), unless, when, zipWithM_) import Control.Monad.Primitive (PrimMonad(..)) import Control.Monad.R.Class import Control.Monad.ST.Unsafe (unsafeSTToIO)@@ -189,12 +190,17 @@ defaultConfig :: Config defaultConfig = Config (Last Nothing) ["--vanilla", "--silent"] (Last (Just False)) --- | Populate environment with @R_HOME@ variable if it does not exist.+-- | Populate environment with @R_HOME@ variable if it does not exist and+-- @R_LIBS@ variable if it doesn't exist either. populateEnv :: IO () populateEnv = do mh <- lookupEnv "R_HOME" when (mh == Nothing) $ setEnv "R_HOME" =<< fmap (head . lines) (readProcess "R" ["-e","cat(R.home())","--quiet","--slave"] "")++ ml <- lookupEnv "R_LIBS"+ when (ml == Nothing) $+ setEnv "R_LIBS" =<< fmap (head . lines) (readProcess "R" ["-e","cat(.libPaths(),sep=if (.Platform$OS.type == \"unix\") \":\" else \";\")","--quiet","--slave"] "") -- | A static address that survives GHCi reloadings which indicates -- whether R has been initialized.
src/Language/R/QQ.hs view
@@ -108,6 +108,15 @@ chop :: String -> String chop name = take (length name - length antiSuffix) name +-- | Map backwards slashes to forward slashes.+#ifdef mingw32_HOST_OS+fixwinslash :: String -> String+fixwinslash str = let+ repl '\\' = '/'+ repl c = c+ in map repl str+#endif+ -- | Find all occurences of antiquotations. -- -- This function works by parsing the user's R code in a separate@@ -130,11 +139,21 @@ Temp.withSystemTempFile "inline-r-.R" $ \input_file input_fh -> do hPutStr input_fh input hClose input_fh- (code, stdout, stderr) <- readProcessWithExitCode "R" ["--slave"] $+ (code, stdout, stderr) <- readProcessWithExitCode "R" ["--slave"] -- Note: --slave was recently renamed to --no-echo. --slave still works -- but is no longer documented. Using the old option name for now just -- in case the user have an older (pre-2020) version of R.- "input_file <- \"" ++ input_file ++ "\"\n" +++ -- + -- Change backslashes to forward slashes in tempFile names + -- under Windows. Windows is tolerant of this Unixification, but + -- Unix systems (and R) are less tolerant of naked backslashes + -- outside of valid escape sequences. For example, + -- str <- "C:\Users\joe" is invalid in R.+#ifdef mingw32_HOST_OS+ $ "input_file <- \"" ++ (fixwinslash input_file) ++ "\"\n" +++#else+ $ "input_file <- \"" ++ input_file ++ "\"\n" +++#endif [Heredoc.there|R/collectAntis.R|] return $ case code of ExitSuccess -> Right $ words stdout
+ tests/test-env1.hs view
@@ -0,0 +1,17 @@+module Main where++import qualified Language.R.Instance as R++import System.Environment+import Test.Tasty+import Test.Tasty.HUnit++tests :: TestTree+tests = testCase "initialize respects R_LIBS env" $ do+ let somePath = "bogusfasdfassomePath"+ setEnv "R_LIBS" somePath+ _ <- R.initialize R.defaultConfig+ (somePath @=?) =<< getEnv "R_LIBS"++main :: IO ()+main = defaultMain tests
+ tests/test-env2.hs view
@@ -0,0 +1,20 @@+{-# LANGUAGE QuasiQuotes #-}+module Main where++import H.Prelude as H+import qualified Language.R.Instance as R++import System.Environment.Blank as BlankEnv+import Test.Tasty+import Test.Tasty.HUnit++tests :: TestTree+tests = testCase "blank R_LIBS does not affect R's stdlib" $ do+ -- use an explcitly blank env R_LIBS="", see `System.Environment.setEnv`+ BlankEnv.setEnv "R_LIBS" "" True+ _ <- R.initialize R.defaultConfig+ ("TRUE" @=?) =<< runRegion+ (fromSomeSEXP <$> [r| deparse(.libPaths() == normalizePath(.Library,winslash="/")) |] :: R s String)++main :: IO ()+main = defaultMain tests