-
Notifications
You must be signed in to change notification settings - Fork 235
Export objects via name vector #531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Can you give me more of an example where you'd use this? |
@hadley My experience with writing R packages is admittedly rather limitied, but here's one specific example from ML that I think is not too contrived. One might want to provide probability estimators for a bunch of binary classifiers in a programmatic manner, according to a common pattern. It might then make sense to write a single unified doc for the family of estimators, and just one doc line to do a batch export. Then something like More concretely: # Suppose `mdl_params` is a list of model-specific parameters, named by S3 method
# Suppose also that `make_estimator()` makes estimators out of those parameters
estprob <- function(x, ...) UseMethod("estprob")
for (mdl in names(mdl_params))
assign(paste0("estprob.", mdl), make_estimator(mdl_params[[mdl]]))
estimators <- paste0("estprob.", names(mdl_params))
#' @exportNames estimators
NULL Technically, that won't work in the current implementation of |
I'd rather provide |
Interesting suggestion. But I'm not sure I understand what you have in mind, exactly. Here's my guess, please correct me if I'm wrong: #' @exportNames names(fs)
NULL with #' @export names(fs)
#' @evalNamespace
NULL Another possibility would be to allow f_nms <- paste0(names(fs), collapse = ",")
#' @evalNamespace export(~f_nms)
NULL But having to put the commas in by hand feels clumsy. |
|
If you still think |
A new PR or issue would be best |
Tag
@exportNames
allows one to export objects using a vector of names. Example:Such a tag is handy if one needs to export batches of closures, say (e.g., in a DSL).