Package 'matlabr'

Title: An Interface for MATLAB using System Calls
Description: Provides users to call MATLAB from using the "system" command. Allows users to submit lines of code or MATLAB m files. This is in comparison to 'R.matlab', which creates a MATLAB server.
Authors: John Muschelli [aut, cre]
Maintainer: John Muschelli <[email protected]>
License: GPL-2
Version: 1.6.0
Built: 2024-11-15 02:50:07 UTC
Source: https://github.com/muschellij2/matlabr

Help Index


Create PATHs to add to MATLAB PATHs

Description

Create PATHs to add to MATLAB PATHs

Usage

add_path(path)

gen_path(path)

add_gen_path(path)

Arguments

path

path to add

Value

A character vector

Examples

add_path("~/")
gen_path("~/")
gen_path("~/")

Find matlab path

Description

This tries to find matlab's path using a system which command, and then, if not found, looks at getOption("matlab.path"). If not path is found, it fails.

Usage

get_matlab(
  try_defaults = TRUE,
  desktop = FALSE,
  splash = FALSE,
  display = FALSE,
  jvm = TRUE,
  figure_windows = TRUE,
  wait = TRUE,
  single_thread = FALSE
)

Arguments

try_defaults

(logical) If matlab is not found from Sys.which, and matlab.path not found, then try some default PATHs for Linux and OS X.

desktop

Should desktop be active for MATLAB?

splash

Should splash be active for MATLAB?

display

Should display be active for MATLAB?

jvm

should JVM be be loaded? If FALSE, then -nojvm

figure_windows

should figure windows be enabled. If not, -noFigureWindows will be called

wait

Should R wait for the command to finish. Both passed to system and adds the -wait flag.

single_thread

Should the flag -singleCompThread be executed to limit MATLAB to a single computational thread?

Value

Character of command for matlab

Examples

if (have_matlab()) {
get_matlab()
}

Logical check if MATLAB is accessible

Description

Uses get_matlab to check if MATLAB's path accessible

Usage

have_matlab()

Value

Logical TRUE is MATLAB is accessible, FALSE if not

Examples

have_matlab()

Convert R matrix to matlab matrix

Description

This function takes in an R matrix then turns it into a matrix in matlab

Usage

rmat_to_matlab_mat(x, matname = NULL, transpose = FALSE)

Arguments

x

matrix of values

matname

Object in matlab to be assigned

transpose

Transpose the matrix

Value

Character scalar of matlab code


Runs matlab code

Description

This function takes in matlab code, where the last line must end with a ;, and returns the exit status

Usage

run_matlab_code(
  code,
  endlines = TRUE,
  verbose = TRUE,
  add_clear_all = FALSE,
  paths_to_add = NULL,
  ...
)

Arguments

code

Character vector of code.

endlines

Logical of whether the semicolon (;) should be pasted to each element of the vector.

verbose

Print out filename to run

add_clear_all

Add clear all; to the beginning of code

paths_to_add

Character vector of PATHs to add to the script using add_path

...

Options passed to run_matlab_script

Value

Exit status of matlab code

Examples

if (have_matlab()){
   run_matlab_code(c("disp('The version of the matlab is:')", "disp(version)"),
   paths_to_add = "~/")
}
## Not run:  
if (have_matlab()){
system.time({ 
run_matlab_code(c("disp('The version of the matlab is:')", 
"disp(version)"), jvm = FALSE, 
figure_windows = FALSE) 
})
   run_matlab_code("disp(version)")
   run_matlab_code("disp(version)", paths_to_add = "~/")
   run_matlab_code(c("x = 5", "disp(['The value of x is ', num2str(x)])"))
}

## End(Not run)

Run matlab script

Description

This function runs a matlab script, and returns exit statuses

Usage

run_matlab_script(
  fname,
  verbose = TRUE,
  desktop = FALSE,
  splash = FALSE,
  display = FALSE,
  jvm = TRUE,
  figure_windows = TRUE,
  wait = TRUE,
  single_thread = FALSE,
  ...
)

Arguments

fname

Filename of matlab script (.m file)

verbose

print diagnostic messages

desktop

Should desktop be active for MATLAB?

splash

Should splash be active for MATLAB?

display

Should display be active for MATLAB?

jvm

should JVM be be loaded? If FALSE, then -nojvm

figure_windows

should figure windows be enabled. If not, -noFigureWindows will be called

wait

Should R wait for the command to finish. Both passed to system and adds the -wait flag.

single_thread

Should the flag -singleCompThread be executed to limit MATLAB to a single computational thread?

...

Options passed to system

Value

Exit status of matlab code


Convert R vector to matlab cell mat

Description

This function takes in an R numeric and returns a status

Usage

rvec_to_matlab(x, row = FALSE, sep = NULL, matname = NULL)

Arguments

x

Numeric vector of values

row

Create row vector instead of column vector

sep

separator to use to separate cells. Will override row argument

matname

Object in matlab to be assigned

Value

Character scalar of matlab code


Convert R vector to matlab cell

Description

This function takes in an R vector then turns it into a cell

Usage

rvec_to_matlabcell(x, sep = ";", matname = NULL, transpose = FALSE)

Arguments

x

Character vector of values

sep

separator to use to separate values. Defaults to ";" argument

matname

Object in matlab to be assigned

transpose

Transpose the cell

Value

Character scalar of matlab code


Convert R vector to matlab cell mat

Description

This function takes in an R vector then turns it into a cell list

Usage

rvec_to_matlabclist(x, matname = NULL)

Arguments

x

Character vector of values

matname

Object in matlab to be assigned

Value

Character scalar of matlab code