You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The documentation indicates that to mock base objects, you should bind them to null somewhere in your package:
Base functions
To mock a function in the base package, you need to make sure that you have a binding for this function in your package. It's easiest to do this by binding the value to NULL. For example, if you wanted to mock interactive() in your package, you'd need to include this code somewhere in your package:
interactive<-NULL
Why is this necessary? with_mocked_bindings() and local_mocked_bindings() work by temporarily modifying the bindings within your package's namespace. When these tests are running inside of R CMD check the namespace is locked which means it's not possible to create new bindings so you need to make sure that the binding exists already.
But I am at a loss as to how this is supposed to work. I am trying to test the following function:
#' Determine operating system#' @return Character string: "windows", "macos", or "linux"get_os<-function() {
if (get_platform()$OS.type=="windows") {
return("windows")
} elseif (get_sysinfo()["sysname"] =="Darwin") {
return("macos")
} else {
return("linux")
}
}
I tried binding the following variables to NULL in my package's globals.R file:
.Platform<-NULLSys.info<-NULL
This successfully got the mock working, but it broke the actual package functionality:
get_os()
Error in if (.Platform$OS.type == "windows") { : argument is of length zero
Which makes sense to me, because by binding to NULL, we are overwriting the R variables our function needs in order to work. What is the logic here, and how do I do this without breaking my package? I also tried this, to no avail:
globalVariables(c(
".Platform",
"Sys.info"
))
The text was updated successfully, but these errors were encountered:
The documentation indicates that to mock base objects, you should bind them to null somewhere in your package:
But I am at a loss as to how this is supposed to work. I am trying to test the following function:
I tried binding the following variables to NULL in my package's globals.R file:
This successfully got the mock working, but it broke the actual package functionality:
Which makes sense to me, because by binding to NULL, we are overwriting the R variables our function needs in order to work. What is the logic here, and how do I do this without breaking my package? I also tried this, to no avail:
The text was updated successfully, but these errors were encountered: