R Arimax Function

I want to make forecast on my data by running an arimax model. The data is like:

Value1, Flag1, Flag2, ................., FlagN
Value2, Flag1, Flag2, ................., FlagN
Value3, Flag1, Flag2, ................., FlagN
Value4, Flag1, Flag2, ................., FlagN
Value5, Flag1, Flag2, ................., FlagN
....
ValueM, Flag1, Flag2, ................., FlagN


So, when I want to make a new forecast, I will provide flag values to the model, then it can give me the forecast value?

How can I prepare the input data? What is the proper R function and proper way of calling?

-
You want the arima function in base R, or the Arima function in the forecast package. auto.arima may be useful as well.
type ?arima into R to read the help page, which gives a good overview for fitting such models. You'll want to split your data into 2 parts: a vector of class ts for "value," and a matrix of your external regressors, which you pass to the xreg argument of the various arima functions.
You can then predict these models using the predict function. You will need to make forecasts of your xregs and pass them to the prediction function in the newxreg argument. You can also use the forecast function in the forecast package to produce confidence intervals and plots. ?predict.Arima in base R and ?forecast.Arima in forecast.