R.matlab
R.matlab copied to clipboard
Error in setFunction example
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; \
")