0

Building a package using testthat for tests; those require an external file which as recommended lies in /tests/testthat/my-file.

However the R CMD check produces

Found the following hidden files and directories:
  tests/testthat/my-file

The above is NOTE (Status: 1 NOTE)

If I add my-file to .Rbuildignore (devtools::use_build_ignore("/tests/testthat/my-file") then the file is well, ignored during the check, thus all tests fail and the package cannot be build.

How can I solve this issue? I understand that a NOTE is passable but I would like to get rid of it nonetheless.

JohnCoene
  • 2,107
  • 1
  • 14
  • 31

1 Answers1

1

The preferred way (according to Hadley) to load API credentials is via environment variables. If you are sharing the credentials with your package, you can just set them in an .onLoad function that will be run with the package namespace is loaded. If you just want to be able to run tests locally using those credentials but not share them, then add them to global Renviron.site file (or, less conveniently, in an .Renviron file in your working directory). Then you can delete this file from your package structure (or just .Rbuildignore it) and make the tests conditional on the presence of the environment variable, with something like:

if (!identical(Sys.getenv("MY_ENV_VAR"), "")) {
  test_all("package")
}
Thomas
  • 43,637
  • 12
  • 109
  • 140