MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by the cyclist
on 20 Jan 2011

Is there a canonical method for calling R from MATLAB, on a Mac?

Answer by Manu Raghavan
on 20 Jan 2011

Accepted answer

*Rscript is a noninteractive variant of the standard R command, designed for just this use.*

I've used Rscript with the --vanilla flag successfully from the OS X command line in the past. To use in MATLAB, this is what I'd consider doing.

1. Prepend the following to the top of myscript.R, the program you want to run:

#! /usr/bin/Rscript

2. From the OS X shell, set the executable bit on your program if it hasn't been done:

$ chmod u+x myscript.R

3. Now, you're set up to use the system function in MATLAB:

>> system('~/path_to/myscript.R')

The usual caveats about paths apply.

the cyclist
on 21 Jan 2011

Thanks. I'll try this. Hopefully it works as well as your git script, which I recently started using!

Answer by Doug Hull
on 20 Jan 2011

The statistics language, R, is not supported in MATLAB; however, the following link contains MATLAB functions on MATLAB Central and File Exchange that may allow communication from MATLAB to R.

the cyclist
on 20 Jan 2011

Thanks for the reply, Doug, but that looks like a Windows-only solution.

## 1 Comment

## Todd Flanagan

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/186#comment_97

Glad to see you here.