'R: What is the working directory when executing covr?
I'm working on a project, where I load a json file. By default, I start the project at the root of the project, however when testing, the path changes. Therefore I included the following statement:
if (grepl("testthat", getwd())) {
template <- jsonlite::read_json("../../templates/initial_status.json")
}else{
template <- jsonlite::read_json("./templates/initial_status.json")
}
This works, however, when using covr::gitlab() the file cannot be opened. I guess the working directory changed and therefore the file is not found:
Error in `open.connection(con, "rb")`: kann Verbindung nicht öffnen
Backtrace:
x
1. \-MyPackage::api_create(...) at test-API.R:40:2
2. \-MyPackage:::get_initial_status(initial_status)
3. \-jsonlite::read_json("../../templates/initial_status.json")
Of course a working around is to use setwd(...) however I don't like this, because I want to publish the package and therefore user may place the package in different locations.
What's the best solution here?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
