Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inline-r fails to run on Mac M1 / M2 #407

Open
idontgetoutmuch opened this issue Mar 6, 2023 · 5 comments
Open

inline-r fails to run on Mac M1 / M2 #407

idontgetoutmuch opened this issue Mar 6, 2023 · 5 comments

Comments

@idontgetoutmuch
Copy link
Member

Describe the bug

[nix-shell:~/Packages/HaskellR]$ stack --nix exec -- H
Language.R.Interpreter: Cannot increase stack size limit.Try increasing your stack size limit manually:$ launchctl limit stack 67104768$ ulimit -s 65532
*** Exception: setResourceLimit: permission denied (Operation not permitted)
ghci> [r| print(.libPaths())        |]
Language.R.Interpreter: Cannot increase stack size limit.Try increasing your stack size limit manually:$ launchctl limit stack 67104768$ ulimit -s 65532

To Reproduce
Steps to reproduce the behavior.

Expected behavior
A clear and concise description of what you expected to happen.

Environment

  • OS name + version:
  • Version of the code:

Additional context
Add any other context about the problem here.

@idontgetoutmuch
Copy link
Member Author

Any update on this? I just tried inline-r = super.haskell.lib.dontCheck (hself.callHackage "inline-r" "1.0.0" {}); and got the same error. I tried the manual instructions but with the same error message.

@facundominguez
Copy link
Member

Hello! I don't have insights on why it doesn't work on Mac, but if you find some other way to set the stack size of the process, or if such setup is no longer needed, the failing setup should be easy to disable here.

@idontgetoutmuch
Copy link
Member Author

--     setResourceLimit ResourceStackSize (ResourceLimits stackLimit stackLimit)
--       `onException` (hPutStrLn stderr $
--                        "Language.R.Interpreter: "
--                        ++ "Cannot increase stack size limit."
--                        ++ "Try increasing your stack size limit manually:"
-- #ifdef darwin_HOST_OS
--                        ++ "$ launchctl limit stack 67104768"
--                        ++ "$ ulimit -s 65532"
-- #elif defined(freebsd_HOST_OS)
--                        ++ "$ ulimit -s 67104768"
-- #else
--                        ++ "$ ulimit -s unlimited"
-- #endif
--                     )

seems to work but now plotting does not

Warning message:
In (function (title, width, height, pointsize, family, antialias,  :
  Unable to create Cocoa Quartz window: NSWindow drag regions should only be invalidated on the Main Thread! (NSInternalInconsistencyException)
*** Exception: R Runtime Error: Error in (function (title, width, height, pointsize, family, antialias,  : 
  unable to create quartz() device target, given type may not be supported

But this does work

{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE ScopedTypeVariables #-}
import H.Prelude as H
import Language.R.QQ

main = H.withEmbeddedR defaultConfig $ do
  H.runRegion $ do
    x <- [r| seq(-4, 4, length=100) |]
    y <- [r| dnorm(x_hs) |]
    _ <- [r| jpeg(file="saving_plot1.jpeg") |]
    _ <- [r| plot(x_hs,y_hs, type = "l", lwd = 2, axes = FALSE, xlab = "", ylab = "") |]
    _ <- [r| dev.off() |]
    return ()

So I can actually do some work now.

Should I create a PR to disable the check for macOS? But what about folks who use pre M1 / M2?

I will create a separate issue for the plotting problem. I tried R on its own and it can plot (I assume via Quartz) so I am not sure why there is a problem via inline-r.

@facundominguez
Copy link
Member

The fact that it fails in the interpreter but not when building a standalone executable hints that H may not be invoking R on the main thread.

H.ghci goes through the trouble of setting -fno-ghci-sandbox. Starting ghci manually and passing the flags from H.ghci manually might help debugging.

Should I create a PR to disable the check for macOS?

We could try that if it works in CI. Ideally, we should test whether setResourceLimit is needed in any platform.

@idontgetoutmuch
Copy link
Member Author

The fact that it fails in the interpreter but not when building a standalone executable hints that H may not be invoking R on the main thread.

I might have confused you. I meant to say that I can't get charts drawn interactively but I can write a chart to a file (dev.off()). It's something to do with Quartz. I think I have seen something like it before.

Should I create a PR to disable the check for macOS?

We could try that if it works in CI. Ideally, we should test whether setResourceLimit is needed in any platform.

It won't be for a few days at least as I may not have internet access.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants