1

I want to open a file from within R.

I can launch the software (graphpad prism) with the following:

system2("C:/Program Files (x86)/GraphPad/Prism 7/prism.exe")

I expected this to open my prism file as if I were double clicking on it or running it from cmd, but it didn't:

system2("H:/Graphs/Shell/Templates/NASH4_Standard.pzfx")

I am receiving the message:

Warning message: running command 'H:/Graphs/Shell/Templates/NASH4_Standard.pzfx' had status 127

I see that this is not an error but just a warning. Am I unintentionally "shelling" the document in the background? How would I make sure it pops up as a window?

Status 127 was addressed here, but for launching the software, not opening the document with it.

Community
  • 1
  • 1
naco
  • 373
  • 1
  • 3
  • 14
  • 1
    Are `.pzfx` files associated with the `prism.exe` application by default? If not, you may need to pass the `.pzfx` file as an argument to the first command. – nrussell Feb 03 '17 at 18:14
  • When I double click a `.pzfx` file, it launches with `prism.exe`. Same if I copy `"H:/Graphs/Shell/Templates/NASH4_Standard.pzfx"` to cmd. Does that mean it is associated? – naco Feb 03 '17 at 18:20
  • 1
    Probably; does `edit(file = "path/to/file.pzfx", editor = "path/to/prism.exe")` work for you? – nrussell Feb 03 '17 at 18:26
  • This works, but without the path. As my working directory was already set to the folder the file was in, `edit(file = "NASH4_Standard.pzfx", editor = "C:/Program Files (x86)/GraphPad/Prism 7/prism.exe")` worked. – naco Feb 03 '17 at 21:15

2 Answers2

3

In Windows environments, you need to call a command line interpreter like CMD prompt or PowerShell. Also, any file path that has spaces needs to be enclosed in double quotes above the quotes needed in R for string literals (the case for your .exe not specific file).

With system() send entire command in one string:

system('cmd /c "H:/Graphs/Shell/Templates/NASH4_Standard.pzfx"')

# POWER SHELL REQUIRES MORE QUOTE ESCAPING (ONLY ONE PAIR W/O SPACES)
system('powershell & """H:/Graphs/Shell/Templates/NASH4_Standard.pzfx"""')

With system2() use the args parameter:

# FILES
system2('cmd', args=c('/c', '"H:/Graphs/Shell/Templates/NASH4_Standard.pzfx"'))
system2('powershell', args=c(' & """H:/Graphs/Shell/Templates/NASH4_Standard.pzfx"""'))

# EXECUTABLES
system2('cmd', args=c('/c', '"C:/Program Files (x86)/GraphPad/Prism 7/prism.exe"'))
system2('powershell', args=c(' & """C:/Program Files (x86)/GraphPad/Prism 7/prism.exe"""'))
Parfait
  • 104,375
  • 17
  • 94
  • 125
2

shell.exec("C:/Program Files (x86)/GraphPad/Prism 7/prism.exe")

does it work for you ?

ps. and shell.exec("MyWorkbook.xls") open file with default program

Qbik
  • 5,885
  • 14
  • 62
  • 93