Search code examples
rrstudiodevtoolstestthat

Difference Ctrl + Shift + T and devtools::test()


What is the differende between the two commands? From RStudio docs it says enter image description here

Thus the two should be identical. However, when I run the following test

testthat::test_that("create_initial_tourplan works", {
  vrp <- package1::createdata()
  dist_mat <- package::calculate_dist_mat(vrp$locations)
  package2::function2(vrp$locations)
})

there are options

  1. Run test line by line => OK
  2. Ctrl + Shift + T => error: 'vrp' not found
  3. devtools::test() => OK

Does anybody have an idea? Obviously, it is not reproducible, so I can't provide more information (except somebody has an idea what I should provide)


Solution

  • The difference can be explained if you look into the settings of the package (Build > Configure Build Tools...):

    If the option Use devtools package functions if available is NOT checked

    • CTRL + SHIFT + T will execute the R files in the tests subfolder of the package (where you normally have one R file that calls testthat via test_check("your_package_name")),

    • otherwise devtools:test() is used which directly calls the tests in the tests/testthat subfolder.

    use devtools package functions if available

    PS: I cannot diagnose what exactly is causing your error message