rstudio / shinytest

Automated testing for shiny apps
https://rstudio.github.io/shinytest/
Other
225 stars 55 forks source link

Failed to start shiny. Error: 'C:\Programs\R-34~1.3/bin/x64/Rterm.exe" -q -e ".libPaths' is not recognized as an internal or externalcommand,operable program or batch file. #169

Closed ghost closed 6 years ago

ghost commented 6 years ago

When I try to call recordTest(), i get this error:

recordTest() Error in sd_startShiny(self, private, path, seed) : Failed to start shiny. Error: 'C:\Programs\R-34~1.3/bin/x64/Rterm.exe" -q -e ".libPaths' is not recognized as an internal or externalcommand,operable program or batch file.

I'm able to run my Shiny app without issue, not sure what's happening here with shinytest.

ghost commented 6 years ago

The path it's attempting to use doesn't look right, but I don't know how to change it or why it's wrong. The path should be C:\Programs\R-3.4.3\bin\x64\Rterm.exe

wch commented 6 years ago

I believe this is due to a bug in R that has been fixed in the development version of R. The issue occurs when a drive does not have short filename enabled -- the buggy versions of R assume that short filename support is enabled. See here: http://r.789695.n4.nabble.com/Bug-Issues-on-Windows-with-SFN-disabled-td4745459.html

In your case, R would think that the directory R-3.4.3 would have a "short" version because it doesn't conform to the 8.3 format -- it has two dots (.) in the name.

The workaround suggested in the email thread is to create a shortname for the directory with fsutil file setshortname.

ghost commented 6 years ago

Thanks for the quick response, I've set a shortname for the directory I installed R into by running:

fsutil file setshortname "C:\Programs\R-3.4.3" R

But now when I attempt to run recordTest() I get this:

> recordTest()
Error in sd_startShiny(self, private, path, seed) : 
  Failed to start shiny. Error: 'C:\Programs\R/bin/x64/Rterm.exe" -q -e ".libPaths' is not recognized as an internal or external command,operable program or batch file.
ghost commented 6 years ago

I'm guessing it comes down to the mix of forward and back slashes. I'm able to run my shiny application on its own without issue though.

wch commented 6 years ago

I did some investigating, and I believe that you are running into this bug: r-lib/processx#94

I am guessing that the output when you run .libPaths() has only one item. Is that correct?

In the meantime, I'll make a workaround for the issue.

wch commented 6 years ago

@shinsukato Can you try installing a specific branch of shinytest and try it out?

To install, first restart R, then run:

devtools::install_github('rstudio/shinytest@fix-windows-quote")

Then try running recordTest() as before.

ghost commented 6 years ago

I get two results when I run .libPaths()

> .libPaths() [1] "C:/Users/<user>/Documents/R/win-library/3.4" [2] "C:/Programs/R-3.4.3/library"

And when I installed the branch you suggest I still get this error:

> recordTest()
Error in sd_startShiny(self, private, path, seed) : 
  Failed to start shiny. Error: 'C:\Programs\R/bin/x64/Rterm.exe" -q -e ".libPaths' is not recognized as aninternal or external command,operable program or batch file.
chasemc commented 6 years ago

I think https://github.com/rstudio/shinytest/issues/169#issuecomment-357690158 is correct, but also the quotations:

I think the result needs to be something like the output of:

# Correct / vs \ with normalizePath, quote path with shQuote (windows default is "Program Files"
# which will break the command because of the space)
pathToR <- shQuote(normalizePath(file.path(R.home("bin"), "R.exe")))

# Replace "-q -e .libPaths" with whatever command you want
commandScript <- paste0(pathToR, " ", "-q -e .libPaths")

# Run command
system(commandScript)
fabiangehring commented 6 years ago

I'm having the same issue on win (latest dev for shiny and shinytest). Unfortunately also the installation of "fix-windows-quote" branch did not solve it. The issue remains when R is installed in C:/R_3_4_3 (and referenced to in RStudio)

tinu-schneider commented 6 years ago

Unfortunately I encounter the same error on Win10.

I dabbled around with the suggestions of @chasemc above and came up with this. It seems like normalizePath() breaks something.

path_to_R <- file.path(R.home("bin"), "Rterm.exe") 
arguments <- "-q -e .libPaths()"

# works
system(paste(path_to_R, arguments))

# but fails with 'normalizePath': Status 127
path_normalized <- normalizePath(path_to_R)
system(paste(path_normalized, arguments))

Perhaps this helps any further...?

Another thing I noticed are the missing brackets in the error message after .libPaths. Should it be .libPaths() with brackets? I have no idea - just noticed...

 Error: "C:\PROGRA~1\R\R-34~1.3/bin/x64/Rterm.exe" -q -e ".libPaths" 

Anyway - I'm looking foreward beeing able to use this amazing package!

wch commented 6 years ago

I've just pushed another change to master that tries to workaround the R windows quoting bug. For those of you affected by this issue, can you re-install and try again?

tinu-schneider commented 6 years ago

Works! Thanks for the update @wch I want to show the main idea of shinytest in a presentation next week - so I'm glad it works :)

wch commented 6 years ago

@tinu-schneider Great to hear!

I'm closing this issue -- if any of you encounter the problem again, please re-open or file a new issue.