Running Code from Files: Scripts
David E. Hiebeler · 2018
Both R and MATLAB have built-in editors and ways to execute commands from their built-in editors and from files. Following standard computer terminology, a file (or editor window) containing some R or MATLAB commands is typically called a script. Both R and MATLAB use what is called a current working directory. The current working directory is the default location for reading and writing files. The command getwd() will display the current working directory. In the OS-X version of R, it is also displayed at the top of the Console window. The command pwd shows (prints) the current working directory, or people can also use cd with no arguments. In addition to the current working directory, MATLAB also has a search path, which is a set of directories it searches when looking for commands. This can be useful if people create some scripts or functions that they may want to use regularly.