In this video I want to talk about 2 things, how to set your working directory and how to edit our code files in Windows. So you can see I've got R started up here, and the first thing you're going to want to do is figure out what your working directory is. Because the working directory is where R finds all of its files for reading and writing on your computer. So you can find out what yur working directory is currently set to be by using the Get WD function. And you can see it's set to be, c:/users/rdbanks/documents. This may differ on your computer. Depending on what version of Windows you're using. and, and what hardware you're using. But there'll be some directory. Probably on your C drive. Now, It, the reason why it's important to know and to set your working directory is because when you read data or when you write things out using functions like read or write CSV, they will be read or written to your home, your working directory. So for example if I do something like read.csv I want to read the say mydata.csv. If the file is not in my working directory, you'll get an error. One that looks much like this because it can't find the file in the working directory. So one possibility is that you can, if you know where this file is, you can move it to your working directory. Or, or you can change your working directory to be wherever this file happens to be. So I can go the File menu here, and choose Change deer. And I'm going to go into my local disk here, users, already paying I go to my desktop here. So now, if I type DIR, I'll get a list of the files that are on my desktop here. In seeing that, lo and behold here is mydata.csv file. So now I can say read.csv and then mydata.csv. And you can see that the data will be printed to the console because now we can find the file in my working directory. So one nice thing, one thing that I suggest that you do for this course, is that perhaps create a single directory or single folder where you can put all of your materials for the course. And not have to worry about them being scattered all over the place. Any time you download something from the website or create a new file, it's probably best to store it all in one folder so that you don't have to be searching all over for it. That way, you can always set your working directory to be that, to be that directory and not have to worry about changing it. So I'm going to minimize R here for a second. I'm going to create a folder on the desktop. Calls I'll just call it Coursera, and then I'm going to use this folder for everything that I do in this course. So if I go back to R here, I can say change working directory again, changed here, and I can go to local disc. Users, RDping. Now this folder is on my desktop, so desktop then it's Coursera here. So now I'm going to say get WD. Let's see the working directory has changed to this Coursera folder. So one of the things you're going to have to do a lot of in this class is to write R code. In order to write R code, you need to be able to use a text editor. luckily, R comes with a rudimentary text editor which will be definitely sufficient for this course. So you can load at the text editor by going to File, and say New Script. And this will give you a blank window, that you can use to write our code. So I'm going to write a simple function here, it's going to be my function [NOISE] it's not going to take any arguments, and all it's going to do it's going to simulate some normal random variables, and then it's going to take the mean of those guys. Alright. So this is a simple function. Now the question is how do I get this R code into my R consoles that I can actually use the function, because you'll notice if I go into my R console here. I type my function. it's, I can't find the function because I haven't loaded into R yet. If I type LS, you'll see that there's nothing in my workspace right now because I haven't loaded any R code into there. So how do I get the R code into the R console? Well there's two ways. If you just have a little bit of code like this function over here, I can click into my R editor. And if just hit hit Ctrl + A to select all, and then Ctrl + C to copy. Then I click back into the console, and I can hit Ctrl + V to paste. Now I've just pasted the code into R and you'll see that if I type LS, I've got my, my function there. I can execute it by just calling it, and you'll see it'll give you the mean of 100 random. Normal random variables, if I do it again, it will give me a slightly different number because it will simulate a different set of numbers. The other thing you can do is go into my R-editor, and you can go to the File menu and click Save As. So now you can, if you save, you can hit Save As, you can save the file into your Coursera folder here, which I'm going to do right now. And you can save it as whatever name you want. So I'm going to call it my code .R. .R is conventional for the extension. So now if I type dir, excuse me. In my console window here, you'll see that there's a file called mycode.r. And you can load this into R, using the source function. So I can say mycode .r. And that loads the all the code that is in this file, of course that's just the my function. So, I haven't done anything new here. But let's say, I want to add another function here. We'll say, second for my second function, and it will take an argument X and it will take X, it will add a little bit of noise to it. So, With the R in arm function. Okay so now I've got two functions here. I can save my file with this little disk icon, or I can go to file, the File menu, hit Save. And I'm going to source this file again. Now, when I type LS, you'll see that I've got this 2nd function there. And I type 2nd, let's say 4. I get a number that's 4, plus a little bit of random noise. So let me get 4 again, lastly the same thing will happen. I could say 4 through 10. And it'll give me each one of those numbers with a little bit of random noise added on. So that's how I edit code, and that's how I load the code into R. Every time you edit your file in the editor, you have to save it and then if you want that code to be available in R, you have to use the source function to source that file back into R. You don't have to use a single file, you can add a new file, so you can say new script. It'll open in another window, you can save this to be a different file if you want. So that way you can separate code for different projects or different assignments. If you close the file here You can always open it back again by hitting, the open button and you can see my code is right there. And if I open it up, you'll see you'll have all your code right back there again. So that's how you edit code in R. There's now there's many other text editors that you might see on the web that you can download, and those are fine to use, but they're not really necessary. The text editor that comes with R should be sufficient for this course.