I want to create a shell extension to run shiny apps in a local process on a Windows 7 Professional 64 bit. I need a command like R -e "shiny::runApp('~/shinyapp')" as defined in the shiny tutorial webpage. I usually create a directory called shiny in every data folder I have. So the supposed command should be always sth like: R -e "shiny::runApp('%1'/shiny) for me."

So I created a key named "Shine!" and a subkey named "command" in HKEY_CLASSES_ROOT\Directory\shell with a value C:\Program Files\R\R-2.15.1\bin\x64\R.exe -e "shiny::runApp('%1/shiny')" The dir structure in regedit is as below:

enter image description here

Now, whenever I right-click the data folder (containing the shiny folder) and click "Shine!", an R console (a cmd console) opens and closes, but the app is not working (the apps are thoroughly checked and working, I also checked the regedit command in cmd).

To be honest, I don't know C, windows shell or any MSDN stuff. I checked several questions, links and documents, but preferred to come up with a simple solution with no error checking (missing folder, etc).

I think I'm missing a syntax error here, so I tried several versions such as only '%1' and right-clicking the shiny folder, also versions like '/'%1/'/shiny' etc. What is wrong and more importantly, how can I debug a right-click with the %1 thing, while the cmd window is closing as quick as hell?


%1 is expanded by the Windows shell to the name of the folder you right-clicked.

So, if the command you want to execute is:

"C:\Program Files\R\R-2.15.1\bin\x64\R.exe" -e "shiny::runApp('%1/shiny')"

you can replace it with a call to cmd.exe that remains open after execution and preserves the double-quotes (by doubling them inside an extra pair of double quotes), so you can check the r.exe's command output:

cmd /k " ""C:\Program Files\R\R-2.15.1\bin\x64\R.exe"" -e ""shiny::runApp('%1/shiny')"" "

I have no experience with R, but my guess is that the runApp command deals badly with the backslashes in the Windows path, or that it contains a space, and I also guess that "~" works with the current directory, as Windows doesn't have a real $HOME directory.

The solution for that is to chain a CD command and the R.exe call via cmd.exe:

cmd /c " cd /d ""%~1"" & ""C:\Program Files\R\R-2.15.1\bin\x64\R.exe"" -e ""shiny::runApp('~/shiny')"" "

(cmd /c closes the new window, cmd /k keeps it open after exectution, so the last example closes the window after launching R.exe).

  • You are probably right about the Windows path error, but I couldn't make the cmd /k work with the quotes. This answer says the correct format for /k switch is sth like cmd /k "code". I tried cmd /k "'C:\Program Files\R\R-2.15.1\bin\R.exe' -e "shiny::runApp('%1')"" but didn't work also. I tried to escape the double quote with ^ or "" according to this question. Could you provide any more examples? – barerd May 13 '13 at 15:02
  • Enclosing sth in quotes in double quotes means using triple quotes around many things. So, now cmd /c "cd %1 & """C:\Program Files\R\R-2.15.1\bin\x64\R.exe""" -e """shiny::runApp("'shiny'")"""" works but /c switch doesn't close the cmd window. It doesn't hurt actually, it's good enough that I don't need to type the whole thing, but is there any trick to close the cmd window? – barerd May 13 '13 at 19:14

Use ProcessMonitor to determine exact arguments and working directory of R started. When you get these values - you can setup your debugger with same settings.

  • You mean technet, right? I tried it and filtered Process Name: Rterm.exe. Whenever I right-click "Shine!", the process number increases by ~3600. I'll try to learn this tool but for now it seems to be an overkill for me. – barerd May 13 '13 at 14:50
  • Why you talking about Rterm.exe when you running R.exe? Filter output by operation. It will be "Start Process" as I can remember ("operation" - "contains" - "process"). This will give you short list easy to analyze. – Maximus May 13 '13 at 17:40
  • Oh I see, operation contains Process start, and then properties shows all the environment and command line etc.. I'm still searching for the right syntax though. – barerd May 13 '13 at 18:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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