-
Notifications
You must be signed in to change notification settings - Fork 9
Description
I have a project with two kinds of R files: "scripts" (which start from the CLI and run the analysis) and "definitions" where I only define functions.
I would like for each function to log in an appropriate logger, for example train_model would log to model/train logger and forecast_model would log to model/forecast and so on.
These methods run thousands of times and I'm a bit curious about the performance. Would it be appropriate to call get_logger at the beginning of the method, storing the logger reference to a local variable, and using that throughout the function?
Or should I have a global object in the environment instead? This seems to be a bit inferior in that name clashes etc. would need to be handled globally ("no lg object for entire program"). Since the definition files are loaded in unspecified order, I feel like the global definitions could easily shadow each other and create a mess (as far as I know there is no such thing as "file local" variable scope in R).
Maybe this is a case of premature optimization, but having no experience with the python logging module which is the inspiration, I'm unsure about the best practices.
It would be also good to have some discussion about this in the readme, e.g. "how to use this package efficiently in a mid/large size project".
Thanks!