The R scripts written for this practical will create in your personal account a directory to save the results of your analyses. For this, R needs to know the name of your home directory.
If you are running the scripts on a Unix or Mac OS X platform, your system automatically defined your home directory in an environment variable called $HOME.
If you are running Windows, the variable $HOME is not defined by default, and you need to specify it yourself. The way to specify environment variables depends on the Windows version (in the AUTOEXEC.bat for early versions, in the system preferences for recent versions). If you don't know how to do it on your machine, you can specify it directly from R with the following protocol.
Sys.getenv("HOME")This will indicate the current contents of the environment variable $HOME.
In Windows Vista, there is an environment variable with your home directory, but its name is USERPROFILE instead of HOME.
## Check if the variable USERPROFILE is defined on your computer Sys.getenv('USERPROFILE') ## If yes, you can define the HOME variable in this way Sys.setenv(HOME=Sys.getenv('USERPROFILE'))
In case the variable USERPROFILE is not defined on your computer, you shoudl find the location of your home directory by your own, and then use it to define, in R, a variable HOME. For example, if your personal folder is "C:\\fred\\", type:
Sys.getenv("HOME")(it should now display "C:\\fred")
## Change working directory to your home directory setwd(Sys.getenv("HOME")) ## Check the value of the working directory getwd()
This script instantiates a series of variables indicating the location of the data files on the web, and the directory where your results will be saved.
You can check the value of these variables with the command
## Print the web location of the course material print(dir.course) ## Print the web location of the data for the practical print(dir.data) ## Print the location of your home directory print(dir.home) ## Print the location of the directory where the results of this practical will be stored. print(dir.results) ## list all the variables defined so far ls()
If you are curious about how the loading was performed, the details can be seen in the two following files, but this is probably not very useful for a first step in R.