Today I Learned in R: RStudio snippets with Jadey Ryan
18:55

Today I Learned in R: RStudio snippets with Jadey Ryan

Equitable Equations 25.05.2026 360 просмотров 20 лайков

Machine-readable: Markdown · JSON API · Site index

Поделиться Telegram VK Бот
Транскрипт Скачать .md
Анализ с AI
Описание видео
Today we're joined by data scientist Jadey Ryan to learn about a hidden gem of an RStudio feature: code snippets. Find the gist that Jadey references at https://gist.github.com/jadeynryan/b7720101ef6613b6a4d943f4fe6865d8 and check out her website at https://jadeyryan.com/. If this vid helps you, please help me a tiny bit by mashing that 'like' button. For more #rstats joy, crush that 'subscribe' button! You can find content supporting this vid on my website (https://equitableequations.com/), which you should totally check out anyway!

Оглавление (4 сегментов)

Segment 1 (00:00 - 05:00)

Hello and welcome to another episode of Today I Learned in R. I'm Andrew Guard of Equitable Equations. I'm here with Greg Martin of our programming 101. And today we have a very special guest, JD Ryan, data scientist at the Washington State Department of Agriculture and uh well-known member, I'd say, of the R community. How you doing, Jadeie? — I'm doing great. Thanks for having me on. — What are you going to teach us about today? Today I'm going to show you R Studios code snippets. So, if you've ever had a snippet of code that you're typing over and over again, uh you want to save yourself some time, it's like a little template where you can just type in a short code and then hit tab, shift tab, and it'll enter that whole little skeleton that you can then fill in like uh attaching packages with library, sourcing, rcripts, um any corto divs. I'll show you some. — Okay. I'm excited about this JD because I'm genuinely here to learn. Okay. So, anybody watching this on my channel, you and I are learning together today because I've never used snippets. So, this is brand new to me. I'm your test audience. Boom. Shakalaka. — Yay. — Should we jump right in with it? You want to go ahead and share a screen or whatever you'd like to do? — Yes, absolutely. So, we're in uh the R Studio IDE and I'm going to just show you what a snippet looks like first and then I'll go into how you can actually configure them. So, say you want to load the tidyiverse and instead of typing out library tidyverse, uh you can actually do lib as the shortcut and then um if you pause for a second, this snippet will show up for their autocomplete feature. So then you can hit tab and then it will move your cursor so that you can actually replace that package with whatever package you want to load. Um and then if you don't want to wait for uh that um autocomplete to show up, you can hit shift tab and then it will it should automatically load the skeleton. — So that's one example library. Another one that I use really frequently is source. So um src and then it will um again highlight where you're supposed to replace that sort of template um or placeholder and then you could put you know R01 load data R. So it's really cool. Um, so to find where all of these snippets are, you'll go to tools and then edit code snippets. And the snippets vary based on what file type you have. So with R, we can see like we have the lib, you have required source, and it has the special syntax. So the uh it uses a tab instead of spaces. So the formatting can be a little bit finicky. Um, but it has like a lot of these pre-built in so you can sort of use these as a template to make more snippets. Um, but this — you didn't build those. Those came pre-installed. — Okay, very good. — Yeah. So, these are pre-installed. Um, and these are like the really common ones that I think the R Studio developers knew that a lot of people um would have a better quality of life by having uh by typing in liib instead of the entire library parentheses and then um their package. So the syntax is like this dollar sign curly brace one is um what tells the IDE where to place your cursor um so that you can autocomplete and replace that placeholder. Um, so some of the other ones that I've added, oh, also, um, taking a step back, some other really helpful ones are like if else commands. Um, especially, you know, if you, — um, uh, don't want to remember where all the curly braces are and all that. So if you just do if shift tab — then you can do um — data uh let's say like length rows greater than one — and then you can you know fill in your uh whatever you want to run if this condition is true. — So uh and then you can do else if. Yeah. So, it's really handy to not have to remember, you know, all the curly braces and the parentheses and all of that. — Um, another one that I really like is, so this is one that I custom built. Um, — is I like to have a standardized header for my R scripts. So, I will type in header and then do shift tab and then

Segment 2 (05:00 - 10:00)

it pre-builds um this like placeholder. So it had it calculates, you know, the um the number of equal signs or dashes or whatever you would prefer. So that way the outline works really nicely. So I love the outline feature where uh you can, you know, navigate easily through your script. Um but then I also have these placeholders where I can put my script name like load data. are and the purpose, you know, like you can fill these out. Um, and the other really cool feature of um the R snippets is that you can actually run our code. So, this date got automatically added. — Yeah. Wow. — Can we see the snippet that's doing that? — Yeah. So, I'll go to tools, edit code snippets again, and then um I'll scroll down to And you can get a little taste of all these snippets. Some of these are I've put in, some of them um are built in. So this is my header script. Um and so it's similar to our markdown or cordo where you do the back tick r and then whatever uh code you actually want run. — Oh, that's so nice. And you can add, you know, your packages that you're constantly adding um to every script, which I think is really handy. Um yeah, so that's just a taste of the R script snippets. — Amazing. Absolutely love it. I've never used this. This is uh this is a complete revelation to me. — That's amazing. I love showing like shortcuts. — Yeah. Yeah. It looks like magic. One use case that immediately comes to mind, it's probably already built in. I almost never write for loops and on the rare occasion that I do, I always forget like the specific syntax and have to, you know, Google something. Yeah, there it is. Exactly. I never can remember if it's an in or do you just type the vector with an equal sign or what? So, — there's a probably a million others like that. Yeah, I think I have like S apply to I don't remember. Yeah, you'd have to browse through and see uh all the um other various ones, but then you also can do a Google search too. Like — this header template um I borrowed from um — let's see, I was looking this up beforehand. Uh this is my little data management plan for work that I have sort of — Oh, wow. to help um guide other folks on my team for code um best practices. — Yes. — Um so where was I was going to see where that was because I want to give credit where credit is due. — Uh Dr. Timothy Farewell's blog post. Although I tried to go to this link and it looks like his website is down. — Okay. — But this is me at least attempting to give credit for Nice. Very good. Very, very good. — Dr. Timothy, if you're out there, we want to see your vlog, man. — Exactly. We love you, man. Get your blog up. — Granted, that was from 2018, so who knows? — So, um, can you mentioned Quartto a little bit ago? Can we use snippets when we're writing a Quartto document as well? — Absolutely. So, um, you, this is an example of using the different, um, file types. So if you want to use a snippet for Cordo or our markdown or just an MD file, um you would add it to this markdown section. — I see. — And so some that I use frequently are panels and columns. So columns are the death of me. — Yes. — Because of the divs. So instead of having to remember and pull up the Cordo website and you know get all the syntax correctly, you can just do column shift tab and voila. — And then you can start doing bullet one. — Yeah. — Bullet two. And then when you're ready to go to the right column, I hit tab and then it automatically put my cursor to replace — the second column placeholder. — Oh wow. Isn't that amazing? You created this snippet. — Yes. — Love it. Absolutely. — That is one I will recreate or um or find because a columns are another one where I always forget how to do them and I always end up looking through my other documents to find a place where I did it or googling it. Um this is lovely. — Yeah. Oh, brilliant. Absolutely brilliant. — Yeah. If it's helpful. Um, I've never used like GitHub gists before, but I've seen those for like sharing little code bits. So, um, I can try to make a gist

Segment 3 (10:00 - 15:00)

of some common code snippets to share with you and then you can link it. — Oh, that would be awesome. — Amazing. — I think everybody would appreciate that. — Yeah. So, this is fun to figure out. Again, though, the um the formatting of these is a little bit finicky. Um, so just making sure to remember like that these are tabs instead of spaces, — otherwise it won't work. Um, — but yeah, these snippets, I mean, I don't use a lot of these other ones, but I'm sure uh there's — folks that will find these useful, — but there's tons and tons of built-in ones. — Yeah. And as you say, there's probably communities out there. You can Google it and there'll be people with snippets that you can just cut and paste and there you go. — Yeah. Another immediate use case for me is um you know one thing I liked about mark our markdown better than Quartto and I have fully switched to Quartto at this point but um the our markdown sort of template document came with a setup chunk — already set up for you um and the CTO template doesn't — it's not a big thing but that's just calling for a snippet. — Yeah, there is one that's just I think R. Yes. And then it does label and options. Okay. And so I prefer the um like cordto uh like this format. — Yep. Me too. Same here. — So you could configure the snippet so that it does this format instead. — Exactly what I'll do. — So — brilliant. — Yeah, — that's great. My next question, Jadeie, is um I know you mentioned that one website where you found the one particular thing, but how did you end up finding out about snippets to begin with? — Oh, that's a good question. — Great to remember. — Great question. Uh — because I feel like this one — sorry — I can't remember actually it's been a very long time. Uh so I probably was from the community. Um it might have been like you know the my favorite part of workshops and any R talk is just when somebody is teaching um like a package or you know like a very focused topic but then they do like a little short code and then somebody in the chat was like whoa I didn't know you could do that. — What was that? Yeah. — Yeah. I'm sure like me learning about snippets was something like that where it wasn't, you know, like a focused like here's a talk on snippets, but it was in instead somebody just doing it and I was like, whoa, how did you do that? — Yeah. You know, kind of thing is — JD, we we'll we'll often be doing these today I learned in R and Andrew will be teaching about like something and in the buildup to him getting into his actual lesson, he'll do a little something and I'll be like, "Dude, didn't know that. " You know what I mean? Like mental note. uh and you land up learning little tips and tricks from just from the way people code, — the way they use R Studio, the way they kind of get to where they're going. — Um especially if you're someone like me who's just sort of very self-learned are in the background in some sort of darkened room trying to do stuff by myself, probably picked up loads and loads of bad habits. — And then you bump into like people like yourselves who are the real deal. You're like, "Okay, there's a actual right way of doing this. " You say that I'm the real deal, but I also was the one who learned in a dark room by myself. I mean, by myself, meaning I'm on Google and looking up community videos and blog posts. — Yeah, I'll tell you a little anecdote. Uh, a lot of us used to use and probably still do use like Stack Overflow where you can pop in a question — and I don't know if they still do this, but back in the day if you asked the question in the wrong format, you'd get kicked off for a week. We went in the sinburn and because they there's a very specific way they wanted the question asked with sort of reproducible data and blah and I kept getting it wrong and I was in the I was a real beginner and I was really trying to figure something out got kicked out and so a week later I got back in uh reformulated the question thinking I got it right same day bam out for another week like oh man and I was it was at a time when I didn't know anybody else that knew R. So I was like on my own uh trying to figure it out. So those were my those were the early days of um trying to figure things. I mean nowadays there's a gazillion ways you can get help. — Well, one thing I do really appreciate about the R community in particular is that there's less of that. I mean you will still run into it and Stack Overflow of course is sort of like the hotbed for what you're just describing. But the R community in general I think has much more of a learning mindset than I've encountered in other uh environments. And I appreciate that a lot. — Yeah. Yeah. 100%. Well, that was super duper useful, Jadeie. Um, yeah, I'm so glad. Would you tell us a little bit about yourselves and yourself and you're welcome to make mention of cats because we happen to know that you've got an interest in cats. So, weave that in to your description of you and R and cats. — The important stuff we all want to know about the cats.

Segment 4 (15:00 - 18:00)

— Yes. — Okay. Well, because you want to see the cats, let me just share my desktop wallpaper so that you can see them. This is Skye, Ty, and Mai. And these are my three rescue snowshoe cats. Um, and you can see them as grown-ups here, too. Um, yeah. So, I Let me also just pull up my website really quick because I have made my whole identity around R and cats. So, I have my little cat logo. Um, and I have stickers of these. So, I will be at Posit this year in Houston. So, if you also will be at Posit, feel free to find me and get some stickers with this cute little cat on it. Um, but yeah, I uh my tagline is catobsessed environmental data scientist. — So, I fully embraced the crazy cat lady. — Love it. — identity. let people know. We'll put a link to that website in the description below in this video on both of our channels. So, you can click on that, go and check it out. It looks really interesting and in a separate conversation, I'd love to talk to you more about the environment and data because I in a part of my professional life amigging into environment and health and analysis and data. So, it's increasingly becoming part of my day job. So, um actually glad to have run into you for that reason. — Of course. Yeah, happy to chat anytime. Last thing I want to say on this is just I think your website which everybody should check out jdrryan. com looks really fabulous and in particular when I was building my CTO website equitable equations. com um a year and a half ago this is one of the places where I sort of code dived code dove to um sort of learn what I was doing. Quartto websites are pretty easy at a basic level, but to make them um look good can be a little bit fiddly and I think you have um a good sense of not just the R code of course, but the um the design principles and how to put them in action. So that's where I really needed the help. — Thank you. Yeah, I um use Sylvia um Canalon. I think I might be saying her name wrong, but um and I love her term that she has on her website, repo. She says, "Happy repo diving. " — Yeah. And that's absolutely another one I dove into. — Yeah. — Yes. Very good. — There's a website somewhere and I don't remember who, but they have a list of sort of like model advanced corto like advanced websites with CTO, mid-tier, and basic. And um I that one was definitely on there as was yours at some level or another. Um yeah, so there's a reason we've all seen these. They're just in the they're in the pop culture at this point. — Yeah, absolutely. — Well, that was fantastic. Um just a quick note to people watching this on my YouTube channel. Go and check out Andrew's channel, Equitable Equations. There'll be a link in the description below. Uh one of my favorite YouTube channels for R and statistics. Always learn stuff from Andrew. He's one of my R heroes. — And while we're at it, if you have not already subscribed to our programming 101, Greg's channel, make sure you get over there and hit that subscribe button right away. — Okay. And uh keep a look out. We're going to have our book out before you know it uh sometime this year hopefully. So, um that'll be a lot of fun. We'll tell you more about that on both of our channels. — Great. Well, thanks again, JD. This is a lot of fun. — Thank you so much for having me. — And great to see you again, Andrew. Great to see you. Take care everybody. — Take care everybody. Boom. Shaka. Don't ever change. Don't do drugs. Always do your best. Rock on.

Другие видео автора — Equitable Equations

Ctrl+V

Экстракт Знаний в Telegram

Экстракты и дистилляты из лучших YouTube-каналов — сразу после публикации.

Подписаться

Дайджест Экстрактов

Лучшие методички за неделю — каждый понедельник