6

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_cataglyphis_iberica/queens/CI23_Q_120828_01.CDF")

in order to carry out an analysis (specified using the /S switch) on a file called CI23_Q_120828_01.CDF, but it seems that no matter what I try the file is not loaded in correctly, presumably because the options are not passed along. Does anyone have a clue what I might be doing wrong?

Right now this command either

  1. doesn't do anything,
  2. makes AMDIS pop up, but it doesn't load the file I specify
  3. gives me the error

    Warning message:

running command 'C:/NIST08/AMDIS32/AMDIS_32.exe /S C:/Users/Ento/Documents/GCMS/test_cataglyphis_iberica/queens/CI23_Q_120828_01.CDF' had status 65535

(I have no idea what results in these different outcomes of the same command)

(the AMDIS command line options are described here at the page 8)

Cheers,
Tom

EDIT:
Found it had to do with forward vs backslashes - running

system("C:\\NIST08\\AMDIS32\\AMDIS_32.EXE C:\\Users\\Ento\\Documents\\GCMS\\test_cataglyphis_iberica\\queens\\CI23_Q_120828_01.CDF /S /E")

seems to work - thank you all for the suggestions!

5
  • 2
    You say /S but have /s in your call. If you open a terminal and type your command as is, does it work?
    – flodel
    Apr 26, 2013 at 23:56
  • changed it to /S, but still no luck unfortunately Apr 27, 2013 at 8:28
  • but main question is how can I properly pass command line options? Apr 27, 2013 at 8:33
  • still, it is is important you test that command directly in a terminal, so you can rule out tons of other things that could be wrong; i.e., maybe you are already passing command line options properly but it is failing for other reasons: wrong options, bad inputs, bad install, etc.
    – flodel
    Apr 27, 2013 at 11:38
  • hmm still no luck, it seems that in the command prompt in Windows C:\NIST08\AMDIS32\AMDIS32$.EXE C:\Users\Ento\Documents\GCMS\test_cataglyphis_iberica\queens\CI23_Q_120828_01.CDF /S /E works OK, but I just don't seem to be able to make this work in R... I think it has to do something with forward & back slashes. Any thoughts? Apr 27, 2013 at 14:55

1 Answer 1

8

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") ) , ... )
15
  • hmm still no luck, it seems that in the command prompt in Windows C:\NIST08\AMDIS32\AMDIS32$.EXE C:\Users\Ento\Documents\GCMS\test_cataglyphis_iberica\queens\CI23_Q_120828_01.CDF /S /E works OK, but I just don't seem to be able to make this work in R... I think it has to do something with forward & back slashes. Any thoughts? Apr 27, 2013 at 14:54
  • My first would be does it work as expected typing it straight into the command line? If so my second thought would be is it something to do with permissions? Try running R with administrator privileges (right click... properties... security... run as... or something vaguely similar) to see if that helps. The forward slashes you see in R will be passed as back slashes to the command line so this isn't the problem. Apr 27, 2013 at 15:10
  • Yes C:\NIST08\AMDIS32\AMDIS32$.EXE C:\Users\Ento\Documents\GCMS\test_cataglyphis_iberica\queens\CI23_Q_120828_01.CD‌​F /S /E typed directly in the Windows command prompt works OK. Also tried with administrator privileges, but no luck still. If I type in R string=shQuote("C:/NIST08/AMDIS32/AMDIS32$.EXE C:/Users/Ento/Documents/GCMS/test_cataglyphis_iberica/queens/CI23_Q_120828_01.CDF /S /E", type = "cmd") system(string) just nothing happens... Apr 27, 2013 at 15:18
  • Ok, try surrounding the second argument with quotes? Also, the $ symbol is an odd thing to have in the name of the executable. I wonder if this is causing problems (but I see why you did this in the docs for calling it from athird party program) Apr 27, 2013 at 15:28
  • 1
    I had one final thought - that perhaps since the file name is passed to the program as an argument perhaps you do need to use backslashes, in which case you can pass them from R by escaping them like this: C:\\Users\\Ento\\Documents\\GCMS\\test_cataglyphis_iberica\\queens\\CI23_Q_120828_01.CD‌​F Please let me know if this works! Apr 27, 2013 at 22:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.