Does anyone have an explanation for the following behaviour?
I have a .R file for documentation. I want to use an internal object for creation of a new object (imported or exported, this does not matter, both result in the same failure)
For my package testpak, I have created an internal object with
data_int <- data.frame(a = 1)
usethis::use_data(data_int, internal = TRUE, overwrite = TRUE)
To build the package, I use an .R file with the following code:
Does not work
#' some_name
#' @description something
#' @return list for each test type
test <- testpak:::data_int
#> Error in get(name, envir = asNamespace(pkg), inherits = FALSE) : object 'data_int' not found
#> ERROR: lazy loading failed for package ‘testpak’
I kind of get the point that somehow there is trouble to find the object in the not yet defined namespace.
But now it gets funny. When I access the same object within a function, the package build works.
#' some_name
#' @description something
#' @return list for each test type
test <- function() testpak:::data_int
#> no error
Another way to make the package build work is by adding usethis::use_data(...) to the code.
Funny enough, it does not actually overwrite the previously written internal object ! (despite using overwrite = TRUE)
#' some_name
#' @description something
#' @return list for each test type
data_int <- data.frame(a = 1)
usethis::use_data(data_int, internal = TRUE, overwrite = TRUE) # does not actually overwrite the previously written internal object
test <- testpak:::data_int
#> no error
sessionInfo()
#R version 3.6.3 (2020-02-29)
#Platform: x86_64-apple-darwin15.6.0 (64-bit)
#Running under: macOS Mojave 10.14.6
#roxygen2_7.1.0