Running a Windows executable file from within R with command line options

后端 未结 1 973
傲寒
傲寒 2021-02-06 09:57

I am trying to call a Windows program called AMDIS from within R using the call

system(\"C:/NIST08/AMDIS32/AMDIS_32.exe /S C:/Users/Ento/Documents/GCMS/test_cata         


        
1条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-06 10:48

    You've heard of bquote , noquote , sQuote, dQuote , quote enquote and Quotes, well now meet shQuote!!! :-)

    This little function call works to format a string to be passed to an operating system shell. Personally I find that I can get embroiled in backslash escaping hell, and shQuote saves me. Simply type the character string as you would on the command line of your choice ('sh' for Unix alikes like bash , csh for the C-shell and 'cmd' for the Windows shell ) wihtin shQuote and it will format it for a call from R using system:

    shQuote("C:/NIST08/AMDIS32/AMDIS_32.exe /S C:/Users/Ento/Documents/GCMS/test_cataglyphis_iberica/queens/CI23_Q_120828_01.CDF" , type = "cmd" )
    #[1] "\"C:/NIST08/AMDIS32/AMDIS_32.exe /S C:/Users/Ento/Documents/GCMS/test_cataglyphis_iberica/queens/CI23_Q_120828_01.CDF\""
    

    More generally, you can use shQuote like this:

    system( shQuote( "mystring" , type = c("cmd","sh") ) , ... )
    

    0 讨论(0)
提交回复
热议问题