The macro package includes several global options to
customize the behavior of msource(). The options can alter
some key parameter defaults. Note that these global options will
override both the parameter defaults, and any local setting on the
function call.
The “echo” parameter of msource() prints the generated
code to the console. In most cases, viewing this generated code is
useful. However, there are some cases where you may want to turn this
feature off. You can do that with the “echo” global option, as such:
When run from the command line or from code, the
msource() function will clear the macro symbol table and
macro function list every time you execute the function. This default
aims to avoid contaminating the symbol table with macro variable values
from the previous run.
On the other hand, the runMSource() addin menu option
sets the “clear” parameter to FALSE. This setting aims to facilitate
interactive usage.
The “clear” settings for both msource() and
runMSource() functions can be forced using the “autoclear”
global option. The syntax is as follows:
By default, RStudio will save unsaved changes in the editor when you push the “Source” button. Similarly, the macro addin will save unsaved changes in the editor when you execute either the “Macro Source” or “Macro Source with Debug” menu items. This behavior can be overridden with the “autosave” option. Here is the syntax:
# Turn autosave off
options("macro.autosave" = FALSE)
# Turn autosave on
options("macro.autosave" = TRUE)
# Remove global option
options("macro.autosave" = NULL)Note that the “autosave” feature only applies to situations when you are running the entire program. If you only select a portion of the code in the editor and run the “Macro Source” addin, the program will not be saved. This exception is identical to the RStudio “Source” button.
Reminder that any global settings will override local parameter settings for all options. If you want to restore priority to the local settings, set the global options to NULL.
Next: Example 1: Listing