Reputation: 125
I'm putting some R code together in a package, and struggling with namespace + import/export problems. It seems that whether or not I add an #' @export
line in roxygen, the functions are still visible to the user. So if I have this file:
#' Function I want the user to see
#'
#' A description
#'
#' @param X a parameter
#' @return the same thing
#' @export
external_function<-function(X){X}
#' Function I don't want the user to see
#'
#' A description
#'
#' @param X a parameter
#' @return the same thing
internal_function<-function(X){X}
both functions end up being exposed, along with library.dynam.unload
and system.file
:
It doesn't seem to make any difference whether the functions are in separate files or not - even if all the functions that shouldn't be exposed are in one file, without any that should, they're still appearing.
Relatedly, all functions from other packages which I import are appearing - I don't know whether this is intended behaviour (it certainly isn't what I wanted!) or whether this is part of the same issue.
#' Function I want the user to see
#'
#' A description
#'
#' @param X a parameter
#' @return the same thing
#' @importFrom dplyr %>%
#' @export
external_function<-function(X){X %>% log}
with this line in the DESCRIPTION file:
Imports:
dplyr
results in:
What am I doing wrong? Is there a way to use functions internally without them being exposed to the user?
Upvotes: 5
Views: 1331
Reputation: 125
The problem was with the way I'd loaded the package, using devtools::load_all()
. Using devtools::load_all(...,export_all=F)
or loading the package without devtools means that only the right functions are exported :).
Upvotes: 5