-2

I would like to call a method in a dll that returns a variable of type 'SEXP' from C#. What is the equivalent of type 'SEXP' in C# or how can I declare a SEXP variable in C#. Thanks in advance.

maniak1982
  • 707
  • 2
  • 7
  • 23
Mat
  • 13
  • 2
  • Best I can tell, the closest equivalent is the `Object` class, but C# and R are very different languages (and I don't know R at all), so I don't know that this information is all that useful. `Object` is the base class for all classes in the .NET library. https://msdn.microsoft.com/en-us/library/system.object%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396 – maniak1982 Jun 03 '15 at 14:49
  • By the way, I think it will be more helpful to ask directly how to call a DLL compiled in C from C#, which has been previously answered. http://stackoverflow.com/questions/11425202/is-it-possible-to-call-a-c-function-from-c-net – maniak1982 Jun 03 '15 at 14:53
  • it's correct, I would like to call a method in a DLL compiled in C from C# but that, I know how to do it but this method receives the SEXP type parameters and returns a SEXP type variable. I do not know how to declare it's parameters and it's return value in C#! – Mat Jun 03 '15 at 18:17
  • I'm not really familiar with how to parse s-expressions myself, but this API was offered up as a solution to a similar question asked previously. It might be a good place to start: http://ometasharp.codeplex.com/ – maniak1982 Jun 04 '15 at 00:38
  • I suspect SEXP is from C, not R (but R uses this C code). – Roman Luštrik Jun 04 '15 at 08:59
  • I just changed the tag, so hopefully somebody with more C experience can help out. – maniak1982 Jun 04 '15 at 13:01

1 Answers1

0

I strongly suggest you use the package https://www.nuget.org/packages/R.NET.Community in your C# project, and you may want to clone or fork R.NET from https://github.com/jmp75/rdotnet to get code examples.

R.NET has all the interop glue code for R's SEXP already available, in C#

For instance in R.NET/REngine.cs

public SymbolicExpression GetSymbol(string name, REnvironment environment) 

The glue code closer to the interop with C is under R.NET/Internals. R.NET uses delegates (Internals/Delegates.cs) to perform PInvoke. Not a compulsory approach, but less cruft code than traditional PInvoke.

REngine inherits from a class to facilitate PInvoke

public class UnmanagedDll

You will find an example how to wrap and call native libraries at https://github.com/jmp75/dynamic-interop-dll

j-m
  • 1,473
  • 1
  • 13
  • 17