Quantcast
Channel: R.NET
Viewing all articles
Browse latest Browse all 1634

New Post: R.NET errors logging

$
0
0
From my experience, errors are thrown in C# (try running rEngine.Evaluate("x = (-1)!")) . It is more problematic with warnings. I found a little hacky way of catching those, though I would also appreciate some advice in how to do this better:
            REngine rEngine = REngine.GetInstance();
            const string __LR_WARNINGS = "warnings";
            const string __WARNINGS_FILE = "warningsFile.txt";

            rEngine.Evaluate(__LR_WARNINGS + " <- file(\"" + __WARNINGS_FILE + "\", open = \"wt\")");
            rEngine.Evaluate("sink(" + __LR_WARNINGS + ", type = \"message\")");

            rEngine.Evaluate("cor( c( 1 , 1 ), c( 2 , 3 ) )");
            
            try { rEngine.Evaluate("close(" + __LR_WARNINGS + ")"); }
            catch (Exception) { }
            rEngine.Evaluate("sink(type = \"message\")");
            rEngine.Evaluate("close(" + __LR_WARNINGS + ")");
            
            String warOrErrs = File.ReadAllText(__WARNINGS_FILE);
            Console.WriteLine(warOrErrs);
The try-catch around the first close is somehow necessary, otherwise the resulting file won't contain anything.

Viewing all articles
Browse latest Browse all 1634

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>