In R: use system() to pass python command with white spaces -


im trying pass python command r (on windows x64 rstudio) python script via command promt. works if type directly cdm not if via r using r function system(). format (this how write in windows cmd shell/promt):

pyhton c:/some/path/script <c:/some/input.file> c:/some/output.file 

this works in cmd promt, , runs script input file (in <>) , gives output file. thought in r do:

system('pyhton c:/some/path/script <c:/some/input.file> c:/some/output.file') 

but gives error python

error: unparsable arguments: ['<c:/some/input.file>', 'c:/some/output.file'] 

it seems if r or windows interpret white spaces different if wrote (or copy-paste) line cmd promt. how this.

from ?system

this interface has become rather complicated on years: see system2 more portable , flexible interface recommended new code.

system2 accepts parameter args arguments of command.

so can try:

system2('python', c('c:\\some\\path\\script', 'c:\\some\\input.file', 'c:\\some\\output.file')) 

on windows:

r documentation not clear on point (or maybe it's me), anyway seems on windows suggested approach use shell() less raw system , system2, plus seems work better redirection operators (like < or >).

shell ('python c:\\some\\path\\script < c:\\some\\input.file > c:\\some\\output.file') 

so command doing is:

  1. call python
  2. telling python execute script c:\some\path\script. here need escape '\' using '\'.
  3. then passing inputs script using '<' operator , input.file
  4. we redirect output (using '>') output file.

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -