Coder Social home page Coder Social logo

rmatlab's Introduction

To call R from within Matlab, you will need to have R compiled as a
shared library.  This needs to be done when compiling R from source
(or via one of the binary distributions that have support for this.)

Download the R source from cran.r-project.org.

  tar zxf R-2.0.0.tar.gz
  ./configure --enable-R-shlib
  make

Then, ensure that this version of R is in your path.
Either install it or put the bin/ directory in your
path.


Install the RMatlab package as a regular R package.

 R CMD INSTALL RMatlab.


================================================================

Running RMatlab.

Tell matlab to look for MEX files in
the directory <R package install directory>/RMatlab/libs
Use the MATLABPATH environment variable for this.

Add $R_HOME/lib/ to the LD_LIBRARY_PATH environment variable
so that the operating system can find the libR.so file
at run-time.

The scripts  RMatlab.csh (tcsh or csh shells) or RMatlab.sh (Bourne (sh) or Bash (bash) shells)
in the scripts/ directory of the _installed_ R package will set things correctly
for you. Just source them into your shell:
  source RMatlab.csh 
or
  . RMatlab.sh

depending on which type of shell you are using.




Set the location of the R installation so that the R engine
can find its code.

  setenv R_HOME `R RHOME`

Set the environment variable LD_LIBRARY_PATH to 

   setenv LD_LIBRARY_PATH $R_HOME/lib

(or $R_HOME/bin for versions of R pre 2.0.0)


Initialize the R engine.

   x = initializeR({'Rmatlab' '--no-save', '--silent'})

Note that the arguments are given using a Matlab cell ({})
rather than a matrix. Any number of recognized arguments
can be passed to R just as one would invoke it from the
command line.



Call a simple R function.

  o = callR('date')

   
  o = callR('rnorm', 10)

    # generate 50 Normal deviates from N(100, 1)
  o = callR('rnorm', 50, 100)

    # Poisson random variable.
  o = callR('rpois', 50, 3)




Calling Matlab from within R.

First, set the LD_LIBRARY_PATH environment
variable to find the relevant Matlab shared libraries.
On Linux, this is 
 <Matlab installation>/bin/glnx86

Now, run R.

 > library(RMatlab)

 > .MatlabInit()

 > .Matlab('magic', 3)


To call Matlab from R that is already within a Matlab session
(i.e. starting from Matlab and calling an R function that itself
calls Matlab), you can use

  .MatlabMexCall

rather than .Matlab.
In the future, there will be numerous other 
functions that one can access and the package
will automatically understand which version to
use.



DTL (Nov, 2 2004)

rmatlab's People

Contributors

duncantl avatar dawnsong avatar

Watchers

 avatar James Cloos avatar

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.