I have a script in R (written by someone else) which calls ImageJ for image analysis using shell() with '-batch' switch:
shell("C:\\ImageJ\\imagej.exe -batch [args]")
The analysis indeed begins, but it seems that R continues to perform the next lines before the analysis is done, and therefore tries to access some files before they are created.
If I run it with a debugger break point,and wait until it's done before I continue, everything works fine. But if I try to run it as a whole, I get an error resulting from reading an empty folder.
The shell() command has an optional argument 'wait' with a default value "TRUE", but I guess that launching ImageJ, and not its completion, is considered as "finish" for shell and that's why R continues. So what can I do to force R to wait until ImageJ is done? I know I can check the number of created files in a while loop, so it will practically hold until all the files are created. But I rather have a more elegant and less dangerous solution. Thanks!