To my knowledge, there's no way reload all command definitions
Ideas for implementation
Inspiration
In R, there's a function in the devtools package that does exactly this: load_all(). While it actually does more, one can basically understand it as running all of the script files that compose a package so that the function definitions contained inside are loaded in memory (and overwrite old definitions). See more in the cheatsheet here, this section of the package dev overview here, and the function docs here.
As an R user/developer, this is a function I use constantly while developing. Both because of muscle memory and some first-principles need to reload my project, I feel myself yearning for this function during Stata-based development.
Implementation
Since adodown packages have a strongly opinionated structure, couldn't we just run all ado files found in src/ado/?
If necessary or desired, perhaps one could attempt to unload definitions in memory by:
Fetching the name of commands for the current version of the package loaded in memory, either parsing the pkg file or getting it from a package-named function that, among other things, returns the names of functions defined in the package (e.g., labeller) or some other reasonably good heuristic.
Iteratively doing cap drop {command_name} to unload the old definitions
To load the definitions of commands from disk, one could probably do something like this:
* let's imagine the package root is given
local pkg_root_dir "pkg/is/here"
* construct the path to package ado directory
local pkg_ado_dir "`pkg_root_dir'/src/ado"
* collect the files in that directory
local ado_files : dir "`pkg_ado_dir'" files "*.ado"
local ado_files : list ado_files clean
* load contents of ado files into memory
foreach ado_file of local ado_files {
include "`pkg_ado_dir'/`ado_file'"
}
Some issues
Where is the package root? reproot resolves this. Unclear how to resolve this cleanly otherwise.
What if the process fails? That's a feature, not a bug. If Stata has some sort of tryCatch mechanism, we could additionally report which ado file failed due to some sort of syntax issues.
What if there are no ado files (yet)? Either load nothing silently or load nothing with an information message (e.g., "No ado files found. Please use ad_command to create a command")
Problem
When developing, one's workflow is:
To my knowledge, there's no way reload all command definitions
Ideas for implementation
Inspiration
In R, there's a function in the devtools package that does exactly this:
load_all()
. While it actually does more, one can basically understand it as running all of the script files that compose a package so that the function definitions contained inside are loaded in memory (and overwrite old definitions). See more in the cheatsheet here, this section of the package dev overview here, and the function docs here.As an R user/developer, this is a function I use constantly while developing. Both because of muscle memory and some first-principles need to reload my project, I feel myself yearning for this function during Stata-based development.
Implementation
Since adodown packages have a strongly opinionated structure, couldn't we just run all
ado
files found insrc/ado/
?If necessary or desired, perhaps one could attempt to unload definitions in memory by:
pkg
file or getting it from a package-named function that, among other things, returns the names of functions defined in the package (e.g., labeller) or some other reasonably good heuristic.cap drop {command_name}
to unload the old definitionsTo load the definitions of commands from disk, one could probably do something like this:
Some issues
tryCatch
mechanism, we could additionally report which ado file failed due to some sort of syntax issues.ad_command
to create a command")