Giter VIP home page Giter VIP logo

simpleembeddedr's Introduction

This is a very simple example of how to embed R in another language. It might be useful for calling R on a when you only need to get text back.

However, R is not reentrant, so this will be racy if running on a server.

Introduction

The function defined here evaluates an arbitrary set of R expressions, and if the the last expression returns a 'string', will return that string.

The interface is generated using SWIG (www.swig.org).

Files

  • SimpleEmbeddedR.i: SWIG definition file,

  • init.h: Declares the funcitons to setup and tear down R,

  • SimpleEmbeddedR.h: Contains the declaration of the exposed function,

  • library_attach.cpp: Calls the functions defined in init.h when the library is attached/detached,

  • SimpleEmbeddedR.cpp: Defines the function declared in SimpleEmbeddedR.h,

  • init.cpp: Defines the functions declared in init.h,

  • embed_java.cpp: C++ side of bindings for Java (generated by SWIG),

  • embedr/: Java classes for the bridge between Java and C++ (generated by SWIG),

  • Tests.java: A Java class that shows how one would use this.

Generating and Compiling Language Bindings

To generate bindings for Java, you would say this:

swig -c++ -java -package "embedr" -o embed_java.cpp -outdir "embedr" SimpleEmbeddedR.i

For Python you would say:

swig -c++ -python -o embed_python.cpp SimpleEmbeddedR.i

Note that to run it, you need to make sure that R.<dll/so> is on the path.

For other languages (and SWIG supports a lot of them), please see the SWIG doco.

You then need to setup your build environment. For windows plebs (like me) you can see how I've setup the environment (for Java and Python) in the visual studio files herein.

with gcc, a line like:

gcc -I/path/to/directory/containing/java/jni/header -I/path/to/directory/containing/java/jni_md/header -I/path/to/R/include/directory -L/path/to/lib/directory -lR --shared -olibSimpleEmbeddedR.so embed_java.cpp init.cpp library_attach.cpp SimpleEmbeddedR.cpp

should do it... though I've not tested this.

Happy to help

If this does not make sense, let me know and I can try and help. I didn't want to write a whole lot more detail here or spend too much time making the code wonderful until I knew that someone is interested.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.