0

I am trying to execute a python script inside an rmarkdown document using bash. This is the code:

python 'path_to_file\file_to_execute.py' --net linear_nn --hid 10

The file requires both --net and --hid arguments to be specified.

When I execute the cell individually in RStudio I can see that it turns the expected output. However, when I go to knit the document (with the above chunk included) I get an error message as follows:

Error in engine(options) : /bin/bash: python: command not found Calls: ... process_group.block -> call_block -> block_exec -> in_dir -> engine In addition: Warning message: In system2(cmd, code, stdout = TRUE, stderr = TRUE, env = options$engine.env) : running command '"bash" -c "python 'path_to_file\file_to_execute.py' --net polar --hid 10 "' had status 127 Execution halted

I have tried the approach of using bash but perhaps that was not the right way to execute python files with arguments in rMarkdown. Would anyone know how to solve this problem so that I can knit the whole document without issue?

Antonio Petricca
  • 8,891
  • 5
  • 36
  • 74
Dom
  • 13
  • 4
  • What happens if you specify an absolute path to a Python binary in your Rmd? eg. `/usr/bin/python 'path_to_file\file_to_execute.py' --net linear_nn --hid 10` – jwalton Mar 30 '22 at 07:45
  • Rather than using an absolute path to a Python binary, another option may be to specify `engine.opts='-l'` in your bash chunk code options. See: https://stackoverflow.com/a/58138894/11021886 for more details – jwalton Mar 30 '22 at 07:47
  • Same outcome in both cases I'm afraid @jwalton – Dom Mar 30 '22 at 08:08

0 Answers0