What is quarto?

What is quarto?

Machine-readable: Markdown · JSON API · Site index

Поделиться Telegram VK Бот
Транскрипт Скачать .md
Анализ с AI

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

Segment 1 (00:00 - 05:00)

Hey everybody. Today we're getting started with Quartto, which is an essential tool when you're doing data science with R. It's going to let us save our results and c and communicate them effectively with other people. In order to start a new quartto document, you can either go to the file menu in our studio or just go up to this little blank piece of paper here in the upper leftand corner and go to quartto document. You'll get a popup window where you're able to give your document a name and select the format. HTML is a good place to start because it just gives you something that pretty much anybody can open and that is pretty flexible in terms of your formatting and so on. Basically, you can just keep all of this for now, all the defaults for now. I'm even going to leave the untitled title as is. When you click create, you'll get a document up in your source pane of our studio. Let me make a little um space for that. And we're just getting sort of a template file that we can modify however we like. There's sort of three different pieces to this and I want to point them out all all out in turn. To start, you have a little bit of a header here, what we call a YAML header. Yet another markdown language just with some metadata and overall instructions about the document. You can see there's a title here. We chose not to specify one before, but we're not committed to that. We can just go back and change it. So, how about uh getting started with Quartto? Great. Um we'll leave the format as HTML for now. As you get more experienced with R, as your Quartto skills increase, you can mess with other formats. Similarly, with the editor, the visual editor is a great place to start out. Ultimately, we'll want to talk about working through the source. The second thing that you'll notice is you just have some basic text here that might look like something you would see in a Microsoft Word or, you know, a Google doc. And you can just, you know, type this as much as you'd like. You know, let's just maybe I'll just add the words hi everybody right there just to illustrate that I can type. Um, you have options for, you know, italics, underline, if you want to make something look like code, do bullets, etc. So, you have some light formatting options here. And you also have a um a place where you can insert, you know, tables, figures, links, etc. Now, you may have also noticed as I was sort of flashing through that, you can insert code chunks. And the thing that makes Quarto kind of special and really useful is that you can insert our code or even code from other languages like Python and have them rendered, have them executed in the document that we're going to generate. So for instance, in the template code, you can see you have a chunk here that just does 1 + 1. So the key thing about quarto is that it's really a twostep process. We create this document that we're looking at right now that includes all of our code and all of the text we want to write, but ultimately this isn't our finished product. This isn't the thing that we're going to share, you know, with our boss, our client, whatever that might be. In order to generate something that's a little bit more public-f facing, we click this render button with a little blue arrow. And then we'll have to save the file because we haven't actually done that yet. We gave it sort of an internal name but didn't actually save it on our computer. So, how about just uh getting started with Quartto. I often give the file and uh the name that I've put earlier the same uh the same thing. Make them the same thing, but that's certainly not required. After we save that, there'll be some internal processes running. And then that Cortto document that we um have been working in, we'll then render and actually create an HTML file that, you know, we might want to share with those other people. And you can see that uh we have basically what we had before. It just it looks a little bit nicer. It's a little bit more public facing. You can see the links, the headings. You can see that the code chunk here oneplus 1 gave both the code and the output. So that's kind of the default in quarto that people can see both what you're getting and how you got it. Um you can set options for your chunks. I don't think I'm going to talk about that too much right now. That's a little bit uh something that kind of comes in later for most people. But you know you might want people to see the output but not the actual code. For instance, um we can make our own chunks, not COD chunks, but code chunks. Um and what you're going to do is to click this sort of green C button. So, let's do that. Click that and get our own code chunk. Now, one of the things I always like to do or almost at the start of my R sessions

Segment 2 (05:00 - 10:00)

Quartto documents is to load up the Tidyverse family of packages. So, let's do that. Let's do library tidyverse right now. And now, when I render the document, that will load up. By the way, you will get an error if you have not yet installed Tidyverse, the Tidyverse family of packages. You do that with install. packages packages parenthesy quote tidyverse over here. I have a whole video. It's the previous one in the my course on um getting started with R. I'll throw a link to that up top. This is helping you get um set up with R Studio. It uh does a few quality of life improvements, things that are going to get you on track for best data science practices right from day one. Among other things, it has you install Tidyverse. So you only need to do that once, but you need to have library tidyiverse in every quarter document where you're going to use those functions. So um the uh the thing that I really want to do here um before I wrap up this video is to import a data set within my quartto document and uh just take a quick glimpse at it. So I have this data set called Erica that I want to import. So um I know that if I click on it and go to import data set I will get a code preview of uh the code that will be needed to actually import this. So I'm just going to copy paste that. I'm going to leave out the view command and I'll talk about why in just a few minutes. Cancel that and then just paste it into my code chunk. So that now when I render this document among the other things that uh that um I've asked R to do or that the template document has asked R to do, I will load up Tidyverse and read Excel, open up those packages and have access to their functions and then read in the Erica data set. And then finally, the last thing I want to do is I will use a function from that tidyiverse family of packages glimpse. And the glimpse command when you pass it a data set like Erica, it will give you a list of all the variable names as well as their types and the first few values. So let's render this and see what the output document looks like. It won't be perfect, of course, but it will uh look better than what we're seeing right here. So after just a moment's delay, here's what we get. We're going to get all the basic output from each of those commands. after library tidyverse we get a message where um R is letting us know all the different packages that were loaded when we did library tidyverse. Similarly after we load read excel and import the Erica data set glimpse will give us that um display of all the different variables we have in this data set their types and the first few values. What we're seeing here is uh Spotify data for Neo Soul artist Erica Badu as of about 2018 I want to say is when I got this data. It might have been a little bit after that. Um fun data set for practice. I will make sure that there is that data set is available to you on my website. There'll be a link to that down below. So if you want to play with this on your own, go for it. All right. So, um, last thing I want to say before we wrap up is, um, just a few best practices and I'm going to type this in. I will also share this Quartto document on that, uh, on that personal website that you can follow with the link to. Um, so I'm going to type this in as I go. A few Quartto best practices. And, uh, this will, as I go through this, it will sort of illustrate I'll it'll give me the opportunity to illustrate um, a couple of other points about CTO. So, first of all, I did a space and then a dash or a dash and then a space, I guess. And Quarto automatically rendered that or previewed that for me as a bullet point. So, that's kind of a nice thing. First of all is um don't include interactive commands, like view. Oh, did you see how I did that, by the way? put the uh the sort of sideways tick and then view and it made it kind of look like code? That's equivalent to format code right there. Just makes it look like an actual R command as opposed to just other text like the word like. Um, another one I wouldn't put is install. packages uh into quarto documents. And the reason is because you know Vue is going to actually open up a pane in R studio. Install. packages packages is going to get on the internet and download some packages, some actual functions onto your machine. These are interactive things that sort of happen in real time and ask R to do things on the fly. Ultimately, what we're trying to do is generate an HTML document that will stand on its own. And so the commands like this can sometimes give you errors or other odd behaviors. Anyway, if you need to do interactive

Segment 3 (10:00 - 13:00)

things, just do them in the console interactively. Um the next thing that you need to know is that you should always um make your docs, your quarto documents self-contained. In other words, they shouldn't rely on anything that's in your working environment or any other commands that you've executed over here beyond just install. packages packages where it's okay to assume that the person rendering this document, which is usually you, have the packages installed. Um, I in sort of going along with that, I want to illustrate um another reason that's important. And so, I'm just going to go back up to this last code chunk and actually execute a couple of these commands. Now, I could copy and paste it over to the console, but there's an easier way. If you're on the line where the command is, you can hit command enter if you're on a Mac or control PC and that command will be sent over to the console and run automatically. So I got my library tidyiverse command right here. So I can do the same thing. Command enter on read excel and read in this data set. If I want to run a whole code chunk, I have a little green arrow here that I can use. Now, one thing that's important to recognize here is that when you do render your document, all of the commands that are run that are listed here are going to get run in order, but they will be run in a new session. In other words, when you click render, R is not going to have access to any of the commands that you may have run over in your console. Just to illustrate that, look what happens if I take out library tidyverse. And you know, I already ran it over here in the console, but I'll run it once again for good measure. If I click render right now, I'm going to get an error. It's going to say, you know, function glimpse not found right there. And even though I have access to the glimpse command through library tidyiverse, just in my working session in the console, Quartto when I render it doesn't have access to that. So, if I want to make this work, I've got to have in the library tidyverse. And now when I hit render, it should all run just fine. Okay, so that should be enough to get you up and running with Quartto. My general advice is that when you're learning R, it's really good. It's really a best practice to save your work by working in a Quartto document and not some other format like for instance a script. This gives you the ability to um not just save your work, but have it print out nicely and in a way that you have a little bit more control over. It um also lets you, you know, take some notes as you go and to actually write down the things that you're doing in real time.

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

Ctrl+V

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

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

Подписаться

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

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