tr8dr / .net-bridge Goto Github PK
View Code? Open in Web Editor NEW.NET Bridge allowing Python and R to access .NET libraries, running either locally or remotely
License: Apache License 2.0
.NET Bridge allowing Python and R to access .NET libraries, running either locally or remotely
License: Apache License 2.0
Will it be possible to access results returned as a reference in the function call argument, like here:
MathNet.Numerics.Distributions.Normal.Samples(System.Double[],System.Double,System.Double)
<summary>
Fills an array with samples generated from the distribution.
</summary>
<param name="values">The array to fill with the samples.</param>
<param name="mean">The mean (μ) of the normal distribution.</param>
<param name="stddev">The standard deviation (σ) of the normal distribution. Range: σ ≥ 0.</param>
<returns>a sequence of samples from the distribution.</returns>
</member>
Is there a way to access constants of a static class? The code would look like
namespace MyNamespace
{
public static class MyConstants
{
public const int CONST_1 = 38;
public const int CONST_2 = 20;
public const int CONST_3 = 100;
...
The version of rDotNet in CRAN is 0.9.1, but unfortunately that version does not handle multiple DLLs in the .cinit...() function (interestingly, the CLRServer in that package DOES handle multiple DLLs).
The github project is up to 0.9.2 and the commit message states that the .cinit function has been extended to handle multiple DLLs ("adjusted rDotNet cinit function to accept multiple dlls")
Is there any chance of publishing version 0.9.2 of rDotNet to CRAN?
Thanks,
Andrew
there seems to be a bug intruduced with issue #3
.Net-Bridge/src/R/rDotNet/R/Driver.R
Line 78 in f39b85d
I have installed the package and dependencies and am attempting to import a custom DLL however I get the following error when attempting to import it.
I would like to know if I am doing something wrong or if this is a known bug.
Traceback (most recent call last):
File ".\test.py", line 10, in <module>
printer = clr.new("Printer.Printer")
File "D:\test\.Net-Bridge\venv\lib\site-packages\pydotnet\clr\CLRApi.py", line 123, in new
return rep.toValue()
File "D:\test\.Net-Bridge\venv\lib\site-packages\pydotnet\clr\data\CLRException.py", line 56, in toValue
raise Exception (self.value)
Exception: System.ArgumentException: could not find type: Printer.Printer
? bridge.common.reflection.Creator.NewInstanceByName(String typename, Object[] args) dans d:\test\.Net-Bridge\src\Python\pyDotNet\server\Library.cs:ligne 16939
? bridge.embedded.CLRBridgeEmbedded.Create(String classname, Object[] parameters) dans d:\test\.Net-Bridge\src\Python\pyDotNet\server\Library.cs:ligne 84
? bridge.server.CLRBridgeServerClient.HandleCreate(CLRCreateMessage req) dans d:\test\.Net-Bridge\src\Python\pyDotNet\server\Library.cs:ligne 1057
WARN [2020-05-29 09:36:27.904]: receipt of messsage failed: System.IO.EndOfStreamException: End of stream reached with 1 byte left to read
à bridge.common.io.SameEndianReader.InternalReadByte() dans d:\test\.Net-Bridge\src\Python\pyDotNet\server\Library.cs:ligne 10400
à bridge.common.io.SameEndianReader.ReadUInt16() dans d:\test\.Net-Bridge\src\Python\pyDotNet\server\Library.cs:ligne 10221
à bridge.server.CLRMessage.Read(IBinaryReader stream) dans d:\test\.Net-Bridge\src\Python\pyDotNet\server\Library.cs:ligne 1422
à bridge.server.CLRBridgeServerClient.Service() dans d:\test\.Net-Bridge\src\Python\pyDotNet\server\Library.cs:ligne 980, stack: à bridge.common.io.SameEndianReader.InternalReadByte() dans d:\test\.Net-Bridge\src\Python\pyDotNet\server\Library.cs:ligne 10400
à bridge.common.io.SameEndianReader.ReadUInt16() dans d:\test\.Net-Bridge\src\Python\pyDotNet\server\Library.cs:ligne 10221
à bridge.server.CLRMessage.Read(IBinaryReader stream) dans d:\test\.Net-Bridge\src\Python\pyDotNet\server\Library.cs:ligne 1422
à bridge.server.CLRBridgeServerClient.Service() dans d:\test\.Net-Bridge\src\Python\pyDotNet\server\Library.cs:ligne 980
Here is the C# file used to generate the dll
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Printer
{
public class Printer
{
public void Print(string text)
{
Console.WriteLine(text);
}
}
}
And here is the python code I am using to import it
import os
virtual_env = os.environ['VIRTUAL_ENV']
print(f"Venv:{virtual_env}")
from pydotnet.clr.CLRApi import CLRApi
clr = CLRApi(hostname="localhost", dll="Printer.dll")
printer = clr.new("Printer.Printer")
printer.Print("HelloWorld!")
Given that I am using a virtualenv I also had to modifiy CLRApi.py l.77 like so
server = "%s/Lib/site-packages/pydotnet/server/CLRServer.exe" % os.environ["VIRTUAL_ENV"]
I am on Windows 10 using python3.6.8
This is the dll file generated
Printer.zip
First, thank you for a developing this awesome solution for accessing .NET from R and Python.
I'm looking for documentation or best practices guidance on using RDotNet and the .Net-Bridge in an R package. My current strategy is to use .cinit
in the .onLoad()
namespace hook to spin up the CLRServer and load the necessary DLL (recognizing that this could cause conflicts with other packages that also use CLRServer, but the solution to #4 would resolve that). What's not clear to me is what I should do when the R session is closed or the package is unloaded. Is there a command to quit the server? Is there any cleanup I need to do to delete objects created by .cnew
? Some additional guidance documents would be helpful.
Hi Jonathan,
I have a further question regarding the rDotNet
package:
Currently one can only load one dll and R
has to be restarted if another dll has to be loaded. The ref-manual states:
the .NET libraries are to be changed, the CLRServer process and R should be restarted.
This behavior in some situations can have some tricky side-effects. For example (to the best of my knowledge) it is not possible to parallely run two R-Scripts (via RScript.exe
) where one R-Script has to load and use a.dll
and the other process b.dll
.
To be honest, I'm not an expert in .NET
at all, but would it be possible to change CLRServer.exe
in a way, that each R-Thread can assemble an own and independent connection to the server. (Like the DBI
package for databases, where it is possible to independently connect to the database (if that is a good example))
Thanks and Cheers
Simon
Sometimes the internal cache dictionaries for ObjectId and objects gets corrupted and the program tries to access a key that does not exist. Currently only fixable by restarting the server.
CLRObjectProxy.cs
Hi,
currently one can only specify one dll-file in the .cinit
function of the rDotNet
package. This could easily be fixed by changing the internal .initialize
function of the rDotNet
package.
First besides the inside functions expand.dll
and or
one had to specify a further function as:
enlarge.dll <- function(dll) {
server.args <- rep(NA, length(dll) * 2)
for (i in 1:length(server.args)) {
if (i%%2 == 1) {
server.args[i] <- "-dll"
} else {
server.args[i] <- dll[[i/2]]
}
}
return(server.args)
}
And change the part where the arguments are sent to CLRServer.exe
if (!is.null(dll))
server.args <- c(server.args, "-dll", enlarge.dll(expand.dll(dll)))
else if (dll.env != "")
server.args <- c(server.args, "-dll", expand.dll(dll.env))
Best Simon
For compatibility with Python 3.10 the import for DataUtil.py need to change:
import numpy as np
import pandas as pd
try:
from collections.abc import Iterable
except ImportError:
from collections import Iterable
from scipy.stats import *
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.