You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Many of my shortcuts have a nearly identical structure and share large parts of their code. In order to reduce duplication I would like to extract shared code into helper functions which are not shortcuts themselves, e.g.
Executing print_foo, this approach leads to the error message Error in print_message("foo") : could not find function "print_message".
Is there a way to modularize the code for shortcuts? I could not find any remarks about this in the documentation.
Thank you very much for this great package!
The text was updated successfully, but these errors were encountered:
This is an interesting idea, thanks for the issue. Right now, shrtcts doesn't source the file containing the shortcuts, instead it parses the file and then runs a labelled function. I've been thinking about ways to expose the function names (which are currently ignored) and in doing so I might need to source the entire script.
I'll have to think about it, but I currently think it's an advantage that the shortcuts R script isn't executed when running a single shortcut. This helps ensure that there aren't any accidental side-effects beyond what's required to run the shortcut function.
One workaround is to put your helper functions somewhere on your computer, e.g. next to the .shortcuts.R file, and then source it from within any shortcut functions that require the helpers.
Thanks for considering this idea. Your concern about undesired side-effects through dependencies within the file is very valid. Thus, sourcing a second .shrtcts_helpers.R file wherever needed is a great workaround for now!
Many of my shortcuts have a nearly identical structure and share large parts of their code. In order to reduce duplication I would like to extract shared code into helper functions which are not shortcuts themselves, e.g.
Executing
print_foo
, this approach leads to the error messageError in print_message("foo") : could not find function "print_message"
.Is there a way to modularize the code for shortcuts? I could not find any remarks about this in the documentation.
Thank you very much for this great package!
The text was updated successfully, but these errors were encountered: