I was modifying my R package and suddenly document()
stopped recognizing the functions I was getting using @importFrom
. The only way I could use my package was to prefix package names (e.g. stringr::str_detect
). Since I have a lot of these, this took a very long time. This started happening after I deleted my NAMESPACE
file because I accidentally left an @importFrom
blank. devtools::document()
still appears to work fine for my other projects. I've noticed lint()
is also seeing these fake problems.
I keep the package files in version control, but haven't seen any obvious reasons it would stop working. What kind of text error could cause this?
Some examples:
I have the following code block defining a utility function in my package:
#' Check if string ends with y.
#' @param x String.
#' @param y String Scalar.
#' @importFrom stringr str_sub str_length
str_ends_with <- function(x, y) {
stopifnot(length(y) == 1)
leny <- str_length(y)
lenx <- str_length(x)
ifelse(lenx < leny, FALSE,
str_sub(x, start = lenx - leny + 1) == y)
}
Yet, lint()
sees
R/util.R:69:11: warning: no visible global function definition for 'str_length'
leny <- str_length(y)
^~~~~~~~~~
R/util.R:70:11: warning: no visible global function definition for 'str_length'
lenx <- str_length(x)
^~~~~~~~~~
Calling roxygen2::roxygenize()
successfully created a new NAMESPACE
file. Usually devtools::document()
can usually do this, but apparently not in my case. However, document()
works as expected afterwards.