System2 within a function


#1

I have an executable (compiled FORTRAN) that uses the terminal to request input for the user and the output goes to different files (e.g., out1.txt, out2.txt). I have created an R function that generates a response file for the executable. Then I can use my response file to get all my output. For example if I run from the command line pm.exe < pm.resp I will get all my outputs (e.g., 1.txt, 2.txt, etc). Now I want to incorporate the whole procedure within R.

If I run from the R console system2("pm.exe", wait = FALSE, invisible = FALSE, stdin = "pm.resp") I get my output with no problem. However If use that line within an R function then I don’t get any output. I tried using system and shell but no luck.


#2

OK this may not help anyone but realize after a lot of pain what was the problem. The function that had system2() was part of a package I was building. Also, I was running a script that was loading a previous version of the function that did not have the system2() command. Because that function was in my global environment; it had precedence over the one created in the package.

If there is any morale about this… If your function is not behaving the way you expect. Check you are calling the right function.