I'm trying to run an exe file by invoking a system command through R's IDE RStudio. My OS is Windows.
I have the following hierarchy for directories:
|_scripts
|_files
|_prog.exe
|_data
|_executed_data
|_case1
|_case2
My exe file is stored at the files directory. The wrangled, ready-to-use data are stored in specific case# directories, where # represents the respective number for that case.
The code is modular. I write functions and then use purrr::map to iterate that function over a vector of the same length as the number of cases.
Here's how the code looks:
#Library(processx)
#Library(purrr)
run_exe = function(directory) {
# Copy .exe file to folder to run
from_dir = c("../files/prog.exe")
to_dir = paste0("../data/executed_data/", directory)
file.copy(from = from_dir, to = to_dir, overwrite = T)
# Run .exe file
processx::run( command = paste0("../data/executed_data/",directory,"/prog.exe" )
}
# Run function over all cases
all_cases = list.files("../data/executed_data")
purrr::map(all_cases, run_exe)
The attempt to run with map fails and a message of error is printed to the console. The printed message says one of the subroutines of the exe file can't find a specific file, hence, the error.
I noticed that the supposed missing file has its name printed in lower case so I renamed the file to make sure all letters were small. Still, it didn't work.
The message also says an error.err file has been printed. This file does get printed when an error happens, however, if I go directly to one of the cases# directory and double click on the exe file, it runs with no problem. Since it runs with no problem, I know there's no missing file.
Given this question deals with running an exe file, I didn't think a reproducible example would be possible. If, however, you have had similar issues when trying to invoke a system function, please share the solution you found.
P.S.: Before using processx::run, I toyed with the system, system2, and sys functions but, again, no success.