In my package I have redefined the find.package function to include custom search locations and would like data() to use my version of find.package() instead of the base version.
I have tried importing utils::data (as below). I have tried assigning data <- utils::data in my package but the namespace of my_package::data() is still utils. I have tried using conflicted.
#' Load data function
#'
#' @name data
#' @rdname data
#' @keywords internal
#' @export
#' @importFrom utils data
#' @usage data(foo)
NULL
If I copy/paste the utils::data() into my package the my_pkg::find.package() is used because the namespaces are the same. But I would prefer not to have an explicitly-coded copy of data in my package.
I just cannot find how (or if) I can import the utils::data() into my package's namespace or convince utils::data() to use my_pkg::find.package() instead of base::find.package()
You should be able to import and re-export the data() function without physically copying the code.
Try removing '@keywords internal' as this conflicts with '@export'. Also '@usage' seems redundant in this context.
Thank you for the suggestion, I tried those changes and have the same problem.
#' Load data function
#'
#' @name data
#' @importFrom utils data
#' @export
NULL
I have made an MWE here that is not working as expected on my computer. There is only one file in R/ that has 3 blocks. Otherwise I think it is a standard usethis template. It can be loaded via devtools::load_all() but you should see the below.
You are correct, in which case I think there is no clean solution but to define a data() function in your package, which masks the one from 'utils' i.e. copy/paste.
The import/re-export is really meant for importing an S3 generic for which you have written a method.
Even if technically you could find a way to move data() into your package's namespace, this would in effect be tampering with an object that does not belong to your package and would probably not be considered best practice / fail R CMD check.