klmr / box

Write reusable, composable and modular R code
https://klmr.me/box/
MIT License
829 stars 47 forks source link

A proposed function to provide `base::getNamespaceExports()` for {box} #369

Open radbasa opened 6 days ago

radbasa commented 6 days ago

This is a proposed solution to provide similar functionality to base::getNamespaceExports().

The implementation is largely a subset of box::use(), box:::use_one(), box:::load_and_register() with the loading packages/modules/functions into the environment removed.

> box::get_exports(dplyr, stringr[str_pad, some_alias = str_trim])
$dplyr
  [1] "slice_max"             "expr"                  "src"  
...
[298] "sql_join"             

$str_pad
[1] "str_pad"

$some_alias
[1] "str_trim"
> options(box.path = "tests/testthat")
> box::get_exports(mod/mod_name, mod/mod_file[nested_module_file])
$mod_name
[1] "this_module_name"     "this_module_name2"    "after_module_attach" 
[4] "function_module_name" "after_package_attach" "nested_module_name"  

$nested_module_file
[1] "nested_module_file"