Wang
Wang

Reputation: 1460

Working with Windows CMD system commands in R returns a "127" error

  1. working with CMD, it works:
"C:\Program Files (x86)\ProteoWizard\ProteoWizard 3.0.21175.5b6d9afee\msconvert.exe" msconvert "C:\Users\Data\QC3.raw" -o "C:\Users\Data"
  1. working with R system(), I got a "127" error:
msconvertpath <- c("C:/Program Files (x86)/ProteoWizard/ProteoWizard 3.0.21175.5b6d9afee/msconvert.exe'")

file <- c("C:/Users/Data/QC1.raw")

outfile <- c("C:/Users/Data")

convert <- paste0(msconvertpath, '"', " msconvert ", '"', file, '"', " -o ", '"', outfile)

system(convert)

Thanks a lot for your help.

Upvotes: 0

Views: 340

Answers (1)

JosefZ
JosefZ

Reputation: 30268

Check your variables in R:

> msconvertpath
[1] "C:/Program Files (x86)/ProteoWizard/ProteoWizard 3.0.21175.5b6d9afee/msconvert.exe'"

You can see an invalid (superfluous) single quote at the very end (before closing double quote), and

> convert
[1] "C:/Program Files (x86)/ProteoWizard/ProteoWizard 3.0.21175.5b6d9afee/msconvert.exe'\" msconvert \"C:/Users/Data/QC1.raw\" -o \"C:/Users/Data"
> 

You can see missing escaped double quotes (opening one for msconvertpath and closing one for outfile).

Adjusted code snippet could work:

msconvertpath <- c("C:/Program Files (x86)/ProteoWizard/ProteoWizard 3.0.21175.5b6d9afee/msconvert.exe")
### ^ removed invalid single quote at the very end (before closing double quote) 
afile <- c("C:/Users/Data/QC1.raw")
outfile <- c("C:/Users/Data")
convert <- paste0('"', msconvertpath, '"', " msconvert ", '"', afile, '"', " -o ", '"', outfile, '"')
### ^ added missing escaped double quotes
system(convert)

The convert variable looks syntactically acceptable now:

> convert
[1] "\"C:/Program Files (x86)/ProteoWizard/ProteoWizard 3.0.21175.5b6d9afee/msconvert.exe\" msconvert \"C:/Users/Data/QC1.raw\" -o \"C:/Users/Data\""

Upvotes: 1

Related Questions