Customizing Properties for R, Python, and Terminal

August 10, 2020

Customizing Properties for R, Python, and Terminal

TPS Fellow Parker Evans

In July 2019 I wrote a post showing how I customize my settings in MATLAB using startup files. This post shows how to make and run startup files in MATLAB, R, Python, and zsh.

Before You Run Your Startup File

When using a scripting environment for a new study it is good practice to clear all variables from the workspace, close all additional windows, and clear the command window. This ensures no left over variables or settings alter your results unexpectedly. Each of these commands is given for MATLAB, R, Python, and zsh in the table below:

Table of commands to clear variables, close windows, clear command window and run startup file for MATLAB, R, Python, zsh

 

 

 

 

 

 

Running Your Startup File

In MATLAB the built-in function "startup" runs the startup file in the beginning of another script. The first line in my MATLAB scripts usually looks like this:

Sample startup code for MATLAB

 

In RStudio having a file named startup.R on the R path. I do not need any additional lines of code at the beginning of R scripts because Rstudio automatically runs startup.R at the beginning of a new session.

Using Python in VSCode allows me to use startup.py on the Python path as my startupfile. The first line in my Python scripts usually looks like this:

plt.close('all'); clear; exec(open("startup.py").read())

Zsh has replaced bash as the default language in MacOS terminal. Using zsh through the Terminal allows me to use a file named .zshrc in the home directory to set settings. Similar to R this method of startup file does not require a command at the beginning of a new session.

What to Put in Your Startup Files

Many of my startup customizations help me make R and Python mimic some of my preferred MATLAB settings. For example, I struggle to remember how to Clear Command Window in R. So I use my R startup file to make the Clear Command Window and Clear All Variables commands the same as in MATLAB (Fig. 1A). My Python startup (Fig. 1B) imports numpy and adds colors from MATLAB. While my zsh startup file keeps Python up-to-date and adds some additional functionality through oh-my-zsh (Fig. 1C). 

Sample script for startup customizations

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Conclusion

My startup files include things like importing modules, setting paths, setting custom colors, and other common commands. If you use the same commands every time you open MATLAB, R, Python, or Terminal consider placing these commands into a startup file for that language.

Written by TPS Fellow Parker Evans

News Filters: