2

I have some problems to call a command line program called molconvert from R using system() in Windows. molconvert is located in "C:\Program Files\ChemAxon\MarvinBeans\bin" I would then like to invoke system() or shell() to mimick what I would achieve by typing

molconvert pdb "C:\molecule conversions\cembrene A.mol"

at the command prompt and collect the resulting output back to R as in

out=system(...,intern=T)

I seem to have trouble though with the backslashes and the spaces in the paths. I tried with

dirmolconvert="C:\\Program Files\\ChemAxon\\MarvinBeans\\bin"
shell(shQuote(paste(dirmolconvert,"\\molconvert pdb "C:\\cembrene A.mol",sep="")))

but that gives me "Error: unexpected symbol in ..." and escaping the " also doesn't help. Any thoughts on how I should resolve this?

or

system(paste(dirmolconvert,"\\molconvert pdb \"C:\\cembrene A.mol\"",sep=""), intern=T)

but that gives me

'C:\Program' not found

Any thoughts?

Edit: Based on the answer below the right way to do this apparently is

inputdir="C:/Users/Ento/Documents/GCMS/molconvert test"
molconvertdir="C:/Program Files/ChemAxon/MarvinBeans/bin"
molecule="cembrene A.mol"
out=system(paste(shQuote(file.path(molconvertdir, "molconvert.bat")),
             "pdb",
             shQuote(file.path(inputdir,molecule))),intern=T)
1
  • If I use this syntax: system('../rgames/test space/norun.bat') I have no error messages. See if you can do the same with your path. Commented Dec 13, 2013 at 14:18

2 Answers 2

3

You want to use shQuote to quote the path to the executable, not the entire command line. Depending on what your molconvert program expects, you may also want to quote paths that are arguments to it.

system(paste(shQuote(file.path(dirmolconvert, "molconvert.exe")),
             "pdb",
             shQuote("C:\\molecule conversions\\cembrene A.mol"))
Sign up to request clarification or add additional context in comments.

1 Comment

Ha many thanks! That did it! And yes, I also need to quote the paths in the argument!
0

the easiest way to fix this is to use short paths:

for %%a in ("C:\molecule conversions\cembrene A.mol") set "sh_path=%%~dpfnxsa"

or

for %%a in ("C:\Program Files\ChemAxon\MarvinBeans\bin") do set "pf_sh_path=%%~dpfnxsa"

and then to pass %sh_path% and %pf_sh_path% as parameter.

2 Comments

Sorry I still don't quite understand - you mean I should put this in a batch file, and then call this batch file from R? But is there no way in which I can do it all directly in R, without first having to make a batch file?
You can call the R from batch and pass these as command line parameters...I've never used R but you can check if you can get short names with it.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.