I've written a macro in imageJ that spits out a data frame which I then analyze in R. I'd love to be able to have the whole procedure work in R without having to first run the macro manually in imageJ. Currently the macro prompts the user for the input and output directories and then does it's thing. I'm thinking there must be a function in R that will allow me to specify the macro and the input and output directories (I could then recode these variables in the macro to somehow take these arguments through the R script?)
I gather that I can use the system() command and found this tantalizing clue from somewhere else on the web:
system("./JavaApplicationStub directory file[i] -batch zmacro")
but I am not sure how to implement this (my macro already utilizes batch processing so that part would be unnecessary).
Thanks to both nograpes & Kota (and more google searching) the problem is solved.
To call an imageJ macro through R is as follows from Kota:
system("/Applications/ImageJ/ImageJ.app/Contents/MacOS/JavaApplicationStub -batch
/Users/xxxx/Desktop/testmacro.txt")
The particular macro I am using requires both input and output directories. To code this in R, I added an argument onto the system call:
system("/Applications/ImageJ/ImageJ.app/Contents/MacOS/JavaApplicationStub -batch
/Users/acgerstein/Desktop/testmacrobatch.txt
/Users/acgerstein/Desktop/130829Pos_24h/*/Users/acgerstein/Desktop/temp/")
As far as I can tell imageJ only supports one argument being passed in. So I separated my input directory and output directories by " * ".
The code in imageJ then looks like this:
folders = getArgument;
delimiter = "*";
parts=split(folders, delimiter);
dir1 = parts[0];
dir2 = parts[1];
The nicest slightly unexpected thing is that the log files that are usually printed through the macro in imageJ now show up in the R console.
Mischief managed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With