HenrikBengtsson / R.matlab

R package: R.matlab
https://cran.r-project.org/package=R.matlab
86 stars 25 forks source link

Error in setFunction example #57

Open EoghanONeill opened 1 year ago

EoghanONeill commented 1 year ago

When there is a space between the equals sign and the function name, the following error message occurs The code does not contain a proper MATLAB function definition

This is from lines 1122 to1125 of https://github.com/HenrikBengtsson/R.matlab/blob/develop/R/Matlab.R

pos <- regexpr("^[ \t\n\r\v]*function[^=]*=[^ \t\n\r\v(]", code)
  if (pos == -1) {
    throw("The code does not contain a proper MATLAB function definition: ", substring(code, 1, 20), "...")
  }

When there is no space, the error message does not occur. Here is an example

 setFunction(matlab, " \
function [win, aver] = dice(B) \
%Play the dice game B times \
gains = [-1, 2, -3, 4, -5, 6]; \
plays = unidrnd(6, B, 1); \
win = sum(gains(plays)); \
aver = win/B; \
")

 setFunction(matlab, " \
function [win, aver] =dice(B) \
%Play the dice game B times \
gains = [-1, 2, -3, 4, -5, 6]; \
plays = unidrnd(6, B, 1); \
win = sum(gains(plays)); \
aver = win/B; \
")