rrstudiotestthat

How can I stop RStudio telling me that symbols are out of scope in my unit tests?


I have followed the instructions at https://testthat.r-lib.org/ for adding unit tests to an R package using the testthat library.

The tests themselves run fine, but RStudio is yellow-squiggle underlining all the functions from both testthat and my package with the message no symbol named 'expect_true' in scope for example (example image below).

A screenshot from RStudio showing some functions underlined with yellow squiggles and a tooltip saying no symbol named 'expect_true' in scope and no symbol named 'is_valid_time, whi' in scope

This is really annoying and I have a "no warnings" mindset when it comes to code so I would like to fix them properly without affecting "genuine" warnings in the tests.

I have I already tried:

  1. Adding a .lintr file to the package root:
linters: with_defaults(
  object_usage_linter = NULL
)
exclusions: list("tests/testthat")
  1. Confirming that both testthat and my package are in tests/testthat.R:
library(testthat)
library(MyPackage)

test_check("MyPackage")

3 Adding export(is_valid_time) to the NAMESPACE file at the package root, which would not solve the testthat calls, but I thought might at least solve the calls into my package functions.

None of these changed the RStudio behaviour (I restarted RStudio to make sure it picked up these changes).


Solution

  • The answer here was to click Build->Load All (Ctrl-Shift-L) (or equivalently run devtools:load_all("path/to/my/project"), which loads the correct things into scope.