Problems with Ctrl+Shift+T - testing a package

Hi there,

I am having some trouble invoking devtools::test() via Ctrl+Shift+T. Seems like this might be an appropriate venue to ask this question.

==> devtools::test()

MY TESTS

Failed -------------------------------------------------------------------------
Error: RStudio not running
Execution halted

Exited with status 1.

I am able to run the tests manually by simply running the code in testthat and am also able to run the tests successfully using devtools::test(). Similarly devtools::check() works fine both from the console and in the build window. So that is, the tests pass, but the Ctrl+Shift+T option doesn't work. And this is a problem because it is such a useful feature. Any ideas?

I am using RStudio version: 1.1.350 and here is my session info:

> sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=English_Canada.1252  LC_CTYPE=English_Canada.1252    LC_MONETARY=English_Canada.1252 LC_NUMERIC=C                   
[5] LC_TIME=English_Canada.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] testthat_1.0.2  devtools_1.13.3

loaded via a namespace (and not attached):
 [1] compiler_3.4.1 magrittr_1.5   R6_2.2.2       tools_3.4.1    withr_2.0.0    rstudioapi_0.7 yaml_2.1.14    crayon_1.3.3   memoise_1.1.0 
[10]  digest_0.6.12  fortunes_1.5-4

Could you show the results of devtools::test()?

I think the "Error: RStudio not running" is probably important.

Here is the full output. The failed tests in the build windows don't output any dots but it does take about as long as the manual console option

> devtools::test()
Loading tidyhydat
Loading required package: testthat
Testing tidyhydat
Testing ANNUAL_INSTANT_PEAKS: ..........
Testing ANNUAL_STATISTICS: ..........
Testing DLY_FLOWS: ..........
Testing DLY_LEVELS: ..........
Testing download_realtime functions: ....
Testing MONTHLY_FLOWS: .........
Testing MONTHLY_LEVELS: .........
Testing SED_DLY_LOADS: .........
Testing SED_DLY_SUSCON: .........
Testing SED_MONTHLY_LOADS: ........
Testing SED_MONTHLY_SUSCON: ........
Testing SED_SAMPLES: .........
Testing SED_SAMPLES_PSD: .........
Testing STATIONS: ........
Testing minor lookup tables for STN_ functions: .....
Testing STN_REGULATION: ........

DONE ===============================================================================================================================================

Hmmm weird. I don't think this is likely to be a problem with the testthat package, so hopefully someone from the IDE team will have some ideas.

I suspect this error message is coming from the rstudioapi package. Are you trying to use that package within your tests? If so, how are you detecting whether RStudio is present as the front-end?

Tried on another machine and wasn't able to replicate the problem. Possibly due to rstudioapi though that isn't part of the tests nor the functions. I will have to work on a way to make this reproducible. Thanks for the response.

crayon is confused, because it uses env variables to detect the color support, and these are set in the build panel. But the build panel does not seem to support color. One workaround would be to unset RSTUDIO_CONSOLE_COLOR in the build pane. I don't think that I can fix this in crayon, because rstudioapi::isAvailable() is not a good test, it also returns FALSE until RStudio is initialized, so it is FALSE in .Rprofile.

The error message is a crayon bug, I assumed that if RSTUDIO is set to 1, then I can call rstudioapi::hasFun("getConsoleHasColor"), but this is not the case.

1 Like

Actually the whole thing is probably a crayon bug. Will fix soon.

1 Like

Should be fixed in the GitHub version of crayon:

devtools::install_github("r-lib/crayon")

Will be on CRAN soon.

Cool, thanks Gabor. The build pane does support color output in RStudio 1.1, but rstudioapi is not available to code running in the build pane.