RStudio Tips and Tricks

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
well thank you guys we're approaching the end so we've had a lot of great talks a lot of thought-provoking talks and this will not be either of those things flat you've all been drinking so we'll see how it goes right so I work at our studio which means I get to talk to a lot of people about using our and using our studio and as I've done that I see people do thing doing things in a really painful way and so that's the goal of this talk is to present everyone here while bemusing are for a long time or just started with a tip or a trick that's one of the things we're like damn I wish I had known about that years ago I've been doing things wrong for so long so that's we're going to talk about we have a little timer and right now it's red so if it like it's to read you can boo me and we'll move on all right so let's get started so but before I show you any of these tips or tricks here's the situation that I find myself in I think a lot of people find themselves in is that you have a project you need to get it done you know there's an easier way to do something but you don't have the time to learn that easier way to do something so you just keep on trekking with your bad habit right because you don't have that time to invest in learning the the tip or the or the trick so this is my main takeaway and my only slide that'll be kind of higher level is sometimes it's worth learning the tip or the tricks even if it takes you you know 10 seconds longer for the first you know month that you're learning all right so I think that applies to all kinds of learning but it's especially a trap that we fall into with these little tiny life-saving things so let's go and look at some of them last year at this conference jay-j they've viewed the our studio notebooks and hopefully you guys have adopted notebooks or at least seen them before they're a really powerful way to interact and do literate data programming but there's also a lot of little tips and tricks that can make your experience with notebooks even better so let's go ahead and look at some of those we're going to hop into a notebook let me see if I can find it so this is a notebook it's just an R markdown document basically and one of the keys to notebooks right is that you can run these code chunks in line so you can click click play on the IDE and you'll see the output as this table if you can page through there's a lot of other ways to run these code chunks so there's a menu here that shows you all these options including the run all option that'll give you this progress bar if you click on the progress bar it will bring you to where it's executing that's a helpful thing to know about another thing that people miss all the time is this little outline button so if you need to jump around and navigate through notebooks quickly you can use the outline to go back and forth between the headers and your Doc's pin something else that's really handy and is pretty recent is that these notebooks support a real time tech preview so if you've ever had to write equations so this gives you a much easier way to do that and preview your work and now this integral is true but don't ask me to prove it and the last thing is in are a lot of times you'll have these notebooks or code chunks that produce more than one type of output and so the notebooks are designed to handle that really effectively so one example if you have a linear model and you called a plot command it generates all these different plots for you automatically and you can scroll through these really quickly and the idea with this gallery view of those plots and you can even you know blow that out and look at it in a separate window if you want so it's a handy way to deal with comparing plots quickly side by side alright so those are some quick tricks for for notebooks a few other things with notebooks so a lot of people think that notebooks are just that in line execution of markdown there's a lot more to it and on the tip of the iceberg that I want to show you is that notebooks support their own output types so this HTML notebook output type and that's a really cool output type it allows you to preview your notebook in an HTML file and I use the word preview very explicitly it's a lot different than knitting when you preview a document it creates this HTML file for you a kind of prettified version of the notebook this HTML file contains your code in your output but unlike knitting the document we didn't rerun the code we just took the output that was in the markdown notebook and stuck it into this HTML file so if you ever run in that problem where it's really painful to knit your document because your code takes a long time to run you can start by just previewing it and you'll get some that great caching behavior these files allow you to hide and view your code so it's a good way to just stick an HTML file on the web that has you know people that aren't in your code can hide the code people that are can take a look at it and then people that are really interested can download the our markdown document so this regular HTML file has some magic that allows it to generate the entire are mark nun document which do you think about it isn't that magical because we just went through and showed you how all the code is inside of there right all right so those are some other tricks on top back I need to re knit my presentation cool so it's just a quick tip I guess so this presentation is written using our markdown so I saw some people using PowerPoint we won't call you out but don't do that all right another thing that a lot of people don't know about is that notebooks I know where our studio and this is New York our conference but you can use other languages inside of these notebooks so if I go back here let's take a look at a notebook that uses sequel so inside of our studio you have this insert button that provides you a drop-down of all the different languages that are supported in the IDE and databases are something we all live with and so the idea makes it really easy to interact with these databases so I want to show you that here I have a code chunk that's going to create a connection to a sequel Lite database kind of a dummy placeholder and my next code chunk I'm going to use that connection so here's that con object but this code chunk is just going to contain verbatim sequel so this is no longer our write I'm just writing sequel code especially handy if you already have some sequel you want to use you can put it in the same place as all your are code if you have some variable and R that you want to use to inform the sequel statement you can do that as well with this handy question mark syntax so we defined min berths for trees in my code chunk and then used it inside of our sequel statement then if you want this nice data set to be available to you in our for later use you can stick in this output VAR argument so now I'm going to run this sequel code chunk and the results are going to go into the our environment I can now go ahead and use R to make a plot or in this case just to print the data frame so that's an example using sequel but we can also do all types of other languages and this is really handy if you are doing an ETL process or maybe you have this whole pipeline and you want to document it in a single place so here's an example we're going to use pandas and the feather was talking about earlier along with Python and R so we're going to start by concatenating some CSV files together with bash and we'll use pandas to read in that ultimate CSV file do some data processing dropping the NA values and then we can use our in the feather package to ingest the data from Python and plot it right so we have all of those different things inside of a single notebook file alright let's hop back to the presentation so we talked about sequel we talked about some ETL processes the other last thing I'll say about notebooks is that they're plain text files and that's very different than if you use the tool like Jupiter so these documents play really nicely with version control so if I see you expand the IDE you can see this project is all versioned with git and so if I make a change to one of these RMD files one of these notebooks I can commit that to github I can look at the dip here and I can you know revert things as necessary so it's a really easy way to keep yourself from making mistakes inside these templates and you can do that with all kinds of other things inside of the ID as well so that's the first time you've seen the get pane it means you're doing something wrong so you shouldn't have to hop into the shell too often to be able to do those cool get manipulations all right so I talked a lot about notebooks but the next thing I want to talk about a next group of tips and tricks is how to save yourself some typing and you might have noticed this in RAM this demo earlier people that are great at are can write code almost as fast as they can think about it right and for a lot of newbies that's a hang-up right if you're just getting start with are I get to spend a lot of time actually like thinking about typing and that's pretty painful for you but it's even more painful for me to watch so we're going to we're going to try to save everyone with some with some tips here so if I'm inside the console one thing I hope you know about our studio is that it comes with really rich auto-completion so if I am looking for dev tools you know the IDE can help you find that and you can use tab to insert the completion statement what a lot of people don't know is that our studio supports this kind of fuzzy matching so say I want to use the dev tools installed github man I do not have to type install github I can type just the unique letters in order so ing H in this case will get me to install github so you can skip as many letters as you want as long as you type them in the correct order and it uniquely defines what you're looking for okay so that's that is the key trick in this talk if you've ever wondered how people can type so damn fast that's the answers they're skipping my tap the letters all right so that's one trick another is code snippets so an R and an I another programming language a lot of what you have to do is write boilerplate code the idea of code snippets is that you can cut down on the amount of boilerplate code you have to write so if I again let's hop into just like an R script one of my favorite code snippets is a shortcut for trading functions so if you type fu n and pause you'll see that snippet is the first thing that comes up at the top there if I hit shift that's going to insert the boilerplate code and then I can just fill in the parts of the boilerplate code that are actually important like the name of the function the variables and then the guts right so just like that I have a pretty stupid function but I didn't have to spend the time actually like writing the word function it's also super handy because I don't have to worry about missing those brackets right you notice ID also enforces that's practices so I get code that looks nice okay so those functions and snippets are really handy if you want to see them you can go to tools global options if you've never seen this window before spend some time diving into those options code snippets are on the code section down here you can click Edit snippets this is all of the snippets that come inside of RC you by default including snippets for other languages and then you can add your own so this last one in here is one that I've created that hopefully it's kind of useful but it gives you a shortcut around the boilerplate for a ggplot2 object so if there's any of your code that you find yourself writing over and over again first check that there's already a snippet for it if there's not pretty easy to make your own alright another thing is never type the same thing twice inside of our studio so this is pretty easy to do our studio records all of your command history so if I go back to the console here let's see I typed something earlier and if I do command up I'll get a history that matches live type so far alright so don't write things twice I think that one of the most underutilized features in the IDE is this history pane the history pane allows you it's not coming up for me but it allows you to of maybe that's why it's underutilized but it as I'm on the daily build of our studio and it's been acting up on me but this history pane contains all the history that you have and one of the cool features that I wish I could show you that I can is that you can easily take things from the history command and inject them either into the console or into a script or a notebook so a lot of times I'll see people like playing around with something in the console and then they go and like copy it from the console and paste it into the script window and then they spend a lot of time like deleting these little arrows that come along for the ride and that just sucks and please never do it alright so once you have gotten down like the disease trick so you don't have to type as much the next thing that can save you a lot of time is learning how to navigate quickly between the different files that you have so this is a really critical keyboard shortcut to learn it's a controlled dot and that opens up this object Explorer it's also available right here and that object Explorer lets you quickly search for files functions objects anything inside your current our project our studio automatically indexes all those things when you open a project and so this search is going to be really fast so for example in that each yell notebook I was showing you I was working with the flight data set so if I type flights it's going to automatically find for me the three or the four CSVs I was interested in but it also knows about the flights object inside the notebook so if I hit enter it's going to pull me up right there it does that really fast because again it's automatically indexing your code so definitely use that again that bar is also supports the fuzzy thing so you don't need to type in the whole whole name it'll figure it out another handy one in the same allure vein is finding files so this will bring up this menu inside of our studio it's very similar but now you specify where you want our studio to search so instead of searching the project you can search wherever you want so if I want to look for the last time I use ggplot I can just point our studio towards my whole workspace and you'll see it finds all the hundreds of times that I've used ggplot and I can quickly hop to any of those examples as well alright so command control dot command shift up or if that's too much to remember I know it's late in the day command capital F same thing alright let's stop this search okay so another thing that people spend a lot of time doing that is painful to watch is they'll navigate through like the file browser and that's just a lot of clicking and it really sucks so what people don't know about let me pull up the the console but you can do the same thing inside of an our script is if you have to quotation marks by default tab search inside of our studio if you're inside of two quotation marks we'll look through your file system so if I have a shiny app inside of a subfolder here I can look at my app hit tab and then app that are in his tab right and I didn't have to spend time typing the name of anything I also don't have to spend time clicking through anything so definitely do that and you can get a pretty tricky here so if you wanted to like go back to your home directory and then start there our Studios might support that definitely supports the parent directory right so there's a lot of different ways that you can walk through your folder structure without using the files pane all right at this point in time after you navigated college different places you probably might be in a situation like me where you have all these tabs open and I've found that there's two types of people there's people that like me have tab anxiety there's people that love tabs have tabs rule their life they have thousands of them so two trips for you if you're either of those people so the first is if you're like me and you don't like having all these tabs open don't go around clicking the X button for all these files like that just it's tiny and it sucks so go to file and there's close close all and close all except current each of those have a keyboard shortcut so I definitely use those that they're handy if you like tabs then another thing that you should take a look at is ctrl shift dot which will bring up wise closed all my tabs so we bring up nothing alright let's open some of these guys great alright so I have a few tabs now if I ctrl shift it will bring up a searchable menu of all the the files that you can quickly look for the one that you're interested in alright so embracing to have anxiety preventing have anxiety you might have already gotten a sense for this but our studio has keyboard shortcuts for everything we even have a keyboard shortcut for sheets for seeing the keyboard shortcuts that's alt shift K will bring up all the different keyboard shortcuts inside of our studio if you want to see them you can go to tools modify keyboard shortcuts that'll show you all of them you can also see the ones that you've changed and you can change them so if there's you don't like the ergonomics of a certain shortcut you can change it the other thing is that our studio has all these hooks inside of it for doing actions and not all of them have a keyboard shortcut by default so if there's something that you find yourself doing a lot like creating a new folder no you can create your own binding so definitely anything that has a button inside the IDE has a programmatic hook that you can tie to a keyboard shortcut alright let's get out of here if you're not happy with that comprehensive list but that's fine in a recent version of our studio we enabled extensibility through adings I'm not going to spend too much time talking about add-ins that you can see some of them here one thing I do want you to know if you're familiar with add-ins or if you use add-ins that you can bind an add-in to a keyboard shortcut as well so if there's really something that's not on that list you can make an add-in for it and then bind it to a keyboard shortcut alright and then lastly I want to talk a little bit about our studio server so we've had a few good talks about pushing our scooter to the cloud but the first trick if you're not aware of this is that our studio does come in more than one flavor and so if you get tired of your code being interrupted by a windows update you can just run our studio on a server and not have to worry about that and then we have to you know support our studio and so we sell this professional version of our studio so I want to show you real quickly some of the paid features that exist in our studio server Pro so I'm going to hop into Chrome and one of the coolest features in here is that I can do project sharing so we've talked a lot about projects that if our CI server Pro you can share a project so if you're working with colleagues can make that process easier and if you are in a shared project you can do collaborative editing so I'm going to spoof this I'm going to put two people inside of the project but they're both me so don't get confused our studio pulls up this icon telling me someone else is inside the project I can choose to follow them and now we're both inside this same file and so if we edit the edits will show up in real time so it's kind of like Google Docs but inside of the IDE all right so hopefully that was kind of a whirlwind tour but hopefully you picked up one or two things that you hadn't seen before that'll be lifesavers for you all of those notebooks if you're interested in them are on github and if you like this kind of thing follow our studio tips on Twitter about once a week will release a tip or a trick that you can hopefully learn so thanks so much Beth [Applause]
Info
Channel: Work-Bench
Views: 52,865
Rating: 4.9337578 out of 5
Keywords: analytics, data science, big data, r conference
Id: kuSQgswZdr8
Channel Id: undefined
Length: 21min 26sec (1286 seconds)
Published: Tue May 16 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.