1 00:00:04,490 --> 00:00:06,650 After working in R, you often want 2 00:00:06,650 --> 00:00:09,930 to save your work so that you can easily re-run commands 3 00:00:09,930 --> 00:00:11,910 and rebuild models. 4 00:00:11,910 --> 00:00:13,660 There are several ways of doing this, 5 00:00:13,660 --> 00:00:15,990 but the method we recommend is by using 6 00:00:15,990 --> 00:00:18,540 what's called a script file. 7 00:00:18,540 --> 00:00:20,680 Let's open a new script file. 8 00:00:20,680 --> 00:00:25,580 Go to File, New Document, on a Mac, and File, New Script, 9 00:00:25,580 --> 00:00:27,590 on a PC. 10 00:00:27,590 --> 00:00:31,140 This will pop up a blank script file. 11 00:00:31,140 --> 00:00:32,940 You can copy and paste any commands 12 00:00:32,940 --> 00:00:36,900 that you've run in your console into the script file. 13 00:00:36,900 --> 00:00:41,620 For example, say we want to save the table commands we ran. 14 00:00:41,620 --> 00:00:44,670 Let's Copy the first table command 15 00:00:44,670 --> 00:00:47,910 and then Paste it into the script file. 16 00:00:47,910 --> 00:00:50,760 We can also take the first tapply command 17 00:00:50,760 --> 00:00:56,980 we ran, Copy and Paste it into our script file. 18 00:00:56,980 --> 00:00:59,440 Now, if you highlight these lines of code 19 00:00:59,440 --> 00:01:04,670 in the script file and press Command-Enter on a Mac, 20 00:01:04,670 --> 00:01:08,950 and Control-r on a PC, it will run these lines of code 21 00:01:08,950 --> 00:01:10,990 in your R console. 22 00:01:10,990 --> 00:01:13,960 So if you save this file and then reopen it 23 00:01:13,960 --> 00:01:18,280 when you start R next time, you can easily rerun any commands 24 00:01:18,280 --> 00:01:20,760 that you ran in this R session. 25 00:01:20,760 --> 00:01:23,260 A lot of times it's easier to just write 26 00:01:23,260 --> 00:01:27,120 commands in your script file and run them in your console 27 00:01:27,120 --> 00:01:31,180 because then they'll always be saved in your script file. 28 00:01:31,180 --> 00:01:34,370 You can add comments in your script file 29 00:01:34,370 --> 00:01:36,000 by using the pound sign. 30 00:01:36,000 --> 00:01:39,100 If you type pound, and then some comment 31 00:01:39,100 --> 00:01:44,120 describing your script file, and then highlight the whole thing 32 00:01:44,120 --> 00:01:47,520 and press Control-r or Command-Enter, 33 00:01:47,520 --> 00:01:50,520 you'll see that the comment runs in the console, 34 00:01:50,520 --> 00:01:52,009 but nothing happens. 35 00:01:52,009 --> 00:01:55,880 R recognizes this as a comment. 36 00:01:55,880 --> 00:01:58,900 If you want to save the output of your R session 37 00:01:58,900 --> 00:02:03,500 in your console, I recommend just saving it as a text file. 38 00:02:03,500 --> 00:02:07,760 In your console, you can go to file, Save to file, 39 00:02:07,760 --> 00:02:12,460 and this will save your output as a text file. 40 00:02:12,460 --> 00:02:14,470 You won't be able to easily rerun 41 00:02:14,470 --> 00:02:17,140 this in R like the script file, but it 42 00:02:17,140 --> 00:02:20,620 will have the summary output of what you did. 43 00:02:20,620 --> 00:02:22,680 When you close R, it will ask you 44 00:02:22,680 --> 00:02:24,900 if you want to save your workspace. 45 00:02:24,900 --> 00:02:27,820 Make sure you have everything you want in a script file 46 00:02:27,820 --> 00:02:31,380 and then don't worry about saving your workspace. 47 00:02:31,380 --> 00:02:33,430 These are the basics of R. We'll see 48 00:02:33,430 --> 00:02:35,780 a lot more in the rest of this class. 49 00:02:35,780 --> 00:02:37,829 But hopefully you've seen in this lecture 50 00:02:37,829 --> 00:02:39,960 how powerful R can be. 51 00:02:39,960 --> 00:02:42,920 In just one lecture, we performed insightful data 52 00:02:42,920 --> 00:02:46,360 analysis on an interesting data set.