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

[Windows only] RProvider doesn't work with R > 4.0.2 #224

Open
Tracked by #267
AndrewIOM opened this issue Sep 20, 2021 · 7 comments
Open
Tracked by #267

[Windows only] RProvider doesn't work with R > 4.0.2 #224

AndrewIOM opened this issue Sep 20, 2021 · 7 comments
Labels
Priority: High Status: Blocked Another issue, pull request, or external dependency is holding up this item. Type: Bug Something is broken!

Comments

@AndrewIOM
Copy link
Collaborator

Thank you for the tips @dsyme. I enabled logging and get the same log output as you. Tracing the code, I think this is an upstream problem caused by an interaction between newer versions of R and a Windows security feature "Control Flow Guard" as mentioned in this RDotNet issue rdotnet/rdotnet#139 (comment). That would also explain why the failure is only happening on windows.

It looks like we'll have to wait for that fix to resolve this windows build problem. But I'll also keep poking at it to see if we can get it to build either on on R <= 4.0.2 or with the workaround noted in that RDotNet issue.

More details:
The s.GetPackages() code seems to be failing after the first call to eval("1+4") because the log doesn't print the 5 after eval("1+4").Value:

    let getPackages() : string[] =
        Logging.logf "Communicating with R to get packages"
        Logging.logf "Test: %O" (eval("1+4"))
        Logging.logf "Test: %O" (eval("1+4").Value)
        eval(".packages(all.available=T)").GetValue()

The above referenced RDotNet issue says calling Evaluate on x64 for R >= 4.0.3 causes crashes. I installed R 4.0.2 and set that as R_HOME to make RProvider use it and the logs a) confirm use of 4.02 and b) get farther. Here the System.Double output should be the results of eval("1+4").

[9/17/2021 11:09:02 AM] [Pid:1484, Tid:1, Apid:1] eval(1+4)
[9/17/2021 11:09:02 AM] [Pid:1484, Tid:1, Apid:1] Output: 
[9/17/2021 11:09:02 AM] [Pid:1484, Tid:1, Apid:1] Converting value from R...
[9/17/2021 11:09:02 AM] [Pid:1484, Tid:1, Apid:1] [DEBUG] MEF Container
[9/17/2021 11:09:02 AM] [Pid:1484, Tid:1, Apid:1] [DEBUG] MEF Container 2
[9/17/2021 11:09:02 AM] [Pid:1484, Tid:1, Apid:1] [DEBUG] MEF Container 3
[9/17/2021 11:09:02 AM] [Pid:1484, Tid:1, Apid:1] Test: System.Double[]

The build tests still hang with the log stopping after trying to do something with Test.RProvider\data/sample.rdata. But the fact that we get farther with 4.0.2 than 4.0.3 is consistent with the problem being caused by the R/RDotNet/Control Guard issue.

Originally posted by @nhirschey in #216 (comment)

@AndrewIOM AndrewIOM added Priority: High Status: Blocked Another issue, pull request, or external dependency is holding up this item. Type: Bug Something is broken! labels Sep 20, 2021
@siavash-babaei
Copy link

It doesn't work with R >= 4.0.2

@nhirschey
Copy link
Contributor

R 4.2.0 is now released with the fix. Below shows R-4.2.0 and RProvider working on windows (albeit with some encoding errors in the SymbolicExpression printer):

#r "nuget: RProvider"

open RDotNet
open RProvider
open RProvider.utils

fsi.AddPrinter FSIPrinters.rValue
R.sessionInfo()

(* Evaluates to
val it: RDotNet.SymbolicExpression =
  R version 4.2.0 (2022-04-22 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22000)

Matrix products: default

locale:
[1] ÿþLC_COLLATE=English_United States.1252ÿþ
[2] ÿþLC_CTYPE=English_United States.1252ÿþ
[3] ÿþLC_MONETARY=English_United States.1252ÿþ
[4] ÿþLC_NUMERIC=Cÿþ
[5] ÿþLC_TIME=English_United States.1252ÿþ

attached base packages:
[1] ÿþgraphicsÿþ  ÿþgrDevicesÿþ ÿþutilsÿþ     ÿþdatasetsÿþ  ÿþmethodsÿþ   ÿþbaseÿþ

loaded via a namespace (and not attached):
[1] ÿþcompiler_4.2.0ÿþ


*)

@matthewcrews
Copy link

Is this working now? I'm looking to use the Type Provider but I've been watching this issue.

@nhirschey
Copy link
Contributor

nhirschey commented Jun 21, 2022

Sort of. It’s still not entirely working out of the box because of some issues with environment variable discoverability (likely the same issues for why R_HOME is t found be default) that prevent it from finding stats.dll

see workarounds here rdotnet/rdotnet#151

@robreno
Copy link

robreno commented Mar 7, 2023

Is this still an issue? I cannot get R to work with F# at all. It is 2023 and this is still not fixed?

@nhirschey
Copy link
Contributor

nhirschey commented Mar 7, 2023

Hi @robreno, I appreciate the frustration but the maintainers are donating their spare time to help here. Nobody is paying them. I'd love to have it fixed, but I myself only have so much time to contribute fixes to this project. Tradeoffs 🤷

This might work for you, assuming you set the R_HOME environment variable. Run the code line by line up until the engine and path are set.

But I'll caveat, there are remaining path and encoding issues, so don't expect things to be smooth.

#r "nuget: RProvider"

open RProvider
open RProvider.stats
open RProvider.utils
open RProvider.Operators

open RDotNet

REngine.SetEnvironmentVariables("c:/program files/r/r-4.2.0/bin/x64", "c:/program files/r/r-4.2.0")

let engine = REngine.GetInstance()
engine.Evaluate("Sys.setenv(PATH = paste(\"C:/Program Files/R/R-4.2.0/bin/x64\", Sys.getenv(\"PATH\"), sep=\";\"))")

R.eval("library(stats)")

fsi.AddPrinter FSIPrinters.rValue

R.mean([1.0; 2.0; 3.0; 4.0; 5.0; 6.0; 7.0; 8.0; 9.0; 10.0])

R.mean([1.0; 2.0; 3.0; 4.0; 5.0; 6.0; 7.0; 8.0; 9.0; 10.0]);;
[1] 5.5
val it: SymbolicExpression =

@nhirschey
Copy link
Contributor

@AndrewIOM as you're thinking about vNext, just FYI there is a Windows UTF encoding bug related to UTF byte order mark (BOM) as shown with the in my prior comment to this thread. #224 (comment) See the "ÿp" characters at the start and end of string entries: [1] ÿþLC_COLLATE=English_United States.1252ÿþ

I have not been able to track down where the bug is introducted. I gave up after awhile but the next things I was going to try were:

  1. Hack of explicitly using regex to remove the "ÿp" BOM before printing.
  2. Perhaps the encoding bug doesn't happen on mac because you sink the output to a file before printing in fsi
    let capturer = if Configuration.isUnixOrMac () then printUsingTempFile else printUsingDevice
    Maybe sinking to a file would fix Windows too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: High Status: Blocked Another issue, pull request, or external dependency is holding up this item. Type: Bug Something is broken!
Projects
None yet
Development

No branches or pull requests

5 participants