-1

I want to automatically run an exe-program (simulation program) with changing input parameters and store the results after every parameter change.

The program has an Exe_Input.txt file where the basic input data is stored. I created another parameter.txt file with one column and 200 rows (numbers). So now I want R to take the first row number, write it in a certain row of the Exe_Input.txt, start the program.exe (maybe with system()-am I right?) and create a result sheet. Then looping from the beginning with the second row of the parameter.txt, starting .exe result sheet and next one... until the end of the parameter.txt.

gung - Reinstate Monica
  • 11,583
  • 7
  • 60
  • 79
UnSF
  • 11
  • 3
  • What have you tried so far? Can you post some code? Also, what is the problem you're facing? It's very unclear what you're asking. – Demitrian Jan 20 '16 at 21:35

1 Answers1

0

It seems like your task boils down to two things:

  1. Reading some data in R
  2. Using that data in system command

The first subject is discussed at lengths at SO and on the net so there is little point in covering it one more time. Broadly speaking, in majority of cases you will need to load into R environment whatever you want to use, fish out, the first line/cell/etc. and pass those values to along with your system syntax.

Launching your app

If I understand your request correctly you are simply interested in passing some string to the system command, on the lines of this discussion. So your code could look like:

system("C:\\me\\my_app.EXE")

Passing parameters is simple, you could make use of the paste function:

paste("C:\\me\\my_app.EXE", "/switch_on", sep = " ")

Naturally, the second element could be created dynamically:

  if (this == that) {
    mySwitch <- "/yes"
  }

Then you would simply use mySwitch in your paste syntax:

paste("C:\\me\\my_app.EXE", mySwitch, sep = " ")

As side point, you may also consider making use of the file.path if you wish to construct a dynamic path to your file.

Alternative approach

If passing single line via system is not enough, you could consider writing your lines to a text file and running a more elaborate batch file. This would be rather exotic solution but if you insist on some deep integration with an external application it may make sense. You could then automatically write a number of lines to your batch file each consisting of command to process another chunk of data or send different command, etc. Or on the lines of this solution you may run your external program in a loop, jumping though bits of data, which probably would make better sense in your case.

Community
  • 1
  • 1
Konrad
  • 17,740
  • 16
  • 106
  • 167
  • Thank you very much for your quick response Konrad. I will look through it tomorrow and try it out. However, maybe I will delay a bit until I'm finished. – UnSF Jan 20 '16 at 23:56