Issue in using Sys.getenv("RSTUDIO") in testthat R package framework

26 Views Asked by At

I have a function written in R and currently in the process of developing the unit test script using testthat package. In my original function, I have an if block which does the below

if(environment == "PROD" & Sys.getenv("RSTUDIO") == 1){

    ESTABLISH JDBC CONNECTION STRING OF PROD DATA IN **R STUDIO**

  } else if(environment == "PROD" & Sys.getenv("RSTUDIO") == ""){

    ESTABLISH JDBC CONNECTION STRING OF PROD DATA IN **SPOTFIRE**

I have the first block of section to execute it in R STUDIO environment and next block for SPOTFIRE. I am getting this checked with Sys.getenv() function. I am able to run the show without any issues in both my environments till now but the problem is with the unit test scripts.

I am using testthat package to write my unit test script and the problem now is when I run the devtools::test() function the tests are running and it is going to the second block of code rather than the first block. I understand that the devtools::test() runs in an isolated framework, is there a way to let the execution go to the first block when I run the test as I don't have any environment variable to handle in the second block for Spotfire so trying to do it in the first half itself.

Any leads would be helpful.

Thanks

0

There are 0 best solutions below