Saturday, December 21, 2013

1.1 Determining the working directory in R

The R console

When opening R, the so-called R console appears. This is the window in which you work with R.
For working with R,  a so-called Working Directory has to be created. This is an
ordinary directory/folder that can simply be created by adding a new folder with the right click of your mouse in Windows Explorer or Finder in Mac OS. In this folder, the Working Directory, all
(data) files are placed with which you want to work with R.
Once this folder is created, specify in R that this created folder is used as the Working Directory dusing the session. This is done as follows:

Showing the current Working Directory of R:

Enter the code getwd() at the R Console, after pressing Enter the location of the R
Working Directory that is currently used appears.

Setting the location of the new Working Directory of R:

If this is the Working Directory that you want to use, you do not have to change it anymore. If you want to use another Working Directory than R displays after entering getwd(), enter
setwd(* LOCATION OF YOUR WORKING DIRECTORY *). This location is easy to find if you click the right mouse button at Explorer (or Finder in Mac OS) and choose for properties (or Info in Mac OS). The location of the folder is displayed in the window, select and copy the location.

Important! In Windows the direction of the slashes in the location could direct in the wrong way (\), manually change this in the command in R (to /).

Figure 3: Location working directory R
Figure 3: Finding the location of the Working Directory 

Inserting the location of the new Working Directory:

Enter the location in the parentheses and quotation marks in the command setwd() in R by placing the mouse pointer between the parentheses and -> Right click-> Paste (or Ctrl + V) quotation marks. Figure 3 shows the location of the Working Directory added in the setwd() command incorrect. It should be done as follows: Setwd('C:/Users/School & Werk.ArieDell/Dropbox/Bedrijf/Data'). As you can see in Figure 4, the working directory is now accepted.

Figure 4: Determining the location of the Working Directory in the R console
Figure 4: Determining the location of the Working Directory in the R console

Checking the current Working Directory

If the above steps are completed, the Working Directory is set successfully. You can check this by using the code getwd() to check the Working Directory are currently is used. By pressing Enter the location you just set as Working Directory is displayed. The set of the Working Directory makes you ready to work with R!


No comments:

Post a Comment