I have a Matlab function that finds the path where this function is within my pc and then runs a bat file on that same directory. This bat file is meant to execute an R script but for a strange reason is failing to do so.
This is my Matlab function:
function [] = myFunction(arg)
% Find the directory of the executing script
thisDir = fileparts(mfilename('fullpath'));
% Save arg as a csv on this directory, this will be read by my R script
tmpDir = strcat(thisDir,'/tmp.csv');
csvwrite(tmpDir,arg);
% Specify the command to run
dosCommand = ['call "' thisDir '/runRscript.bat"'];
dos(dosCommand);
end
The bat file has the following code:
"C:\Program Files\R\R-3.2.2\bin\x64\R.exe" CMD BATCH runRScipt.R
When I run the function in Matlab I get the below message:
C:\Users\...mypath...>"C:\Program Files\R\R-3.2.2\bin\x64\R.exe" CMD BATCH runRscript.R
Since I get this message in Matlab I have no doubt it is finding and reading the batch file, but it fails to execute the R script. I know the bat file works as expected since I can run it through the command line (with the command that should be the "dosCommand" on the Matlab script) or by clicking twice on the .bat file.