image: thumbnail.jpg
R Markdown Advanced Tips to Become a Better Data Scientist & RStudio Connect | With Tom Mock
In this presentation, Tom Mock will teach you some advanced tips that will let you get the most out of R Markdown. Additionally, RStudio Connect will be highlighted, specifically how it works wonderfully with tools like R Markdown.
Please provide feedback: https://docs.google.com/forms/d/e/1FAIpQLSdOwz3yJluPR2fEqE0hBt92NtKZzzNACR8KJhHUt9rhFj3HqA/viewform?usp=sf_link
More resources if you're interested: https://docs.google.com/document/d/1VKGs1G9GcQcv4pCYFbK68_LDh72ODiZsIxXLN0z-zD4/edit
04:15 Literate Programming
09:00 - Rstudio Visual Editor Demo
15:44 - R and python in same document via {reticulate}
18:10 - Q&A: Options for collaborative editing (version control, shared drive etc.)
19:30 - Q&A: Multi-pane support in Rstudio
20:46 Data Product (reports, presentations, dashboards, websites etc.)
24:15 - Distill article
26:27 - Xaringan presentation (add three dashes --- for new slide)
28:58 - Flexdashboard (with shiny)
30:30 - Crosstalk (talk between different html widgets instead of {shiny} server)
35:03 - Q&A: Jobs panel -- parallelise render jobs in background
36:50 - Q&A: various data product packages, formats
39:35 Control Document (modularise data science tasks, control code flow)
39:58 - Knit with Parameters (YAML params: option)
41:20 - Reference named chunks from .R files (knitr::read_chunk())
43:00 - Child Documents (reuse content, conditional inclusion, {blastula} email)
47:07 Templating (don't repeat yourself)
47:38 - rmarkdown::render() with params, looping through different param combinations
49:30 - Loop templates within a single document
50:40 - 04-templating/ live code demo
54:37 - {whisker} vs {glue} -- {{logic-less}} vs {logic templating}
55:30 - {whisker} for generating markdown files that you can continue editing
57:49 RMarkdown + Rstudio Connect
1:00:41 Follow-up Reading and resources
1:04:49 Q&A - {shiny} apps, {webshot2} for screenshots of html, reading in multiple .R files, best practice for producing MSoffice files, {blastula}
Transcript#
This transcript was generated automatically and may contain errors.
Hey, everybody. Welcome to the RStudio live stream. We're going to be covering a few different things today. Namely, we're going to be going over a lot of R Markdown here from my home here in Texas. So really excited to be here with everybody today. I'm going to get some questions in the chat. We'll do a little bit of live coding. I've got a slide deck. I hope you're going to learn something with me today. And we're going to have fun doing this as an experiment. This is one of my first times live streaming and first time here on YouTube live. I've done a little bit on Twitch. So excited to kind of learn along with all of y'all as we go through this experiment. Let me know if you have any questions and we'll try to answer some of them in the chat. And at the very end, we'll also upload the video to YouTube. One of my colleagues is going to be answering questions in the chat as well and sharing some links as long as we go. So let's get kicked off. I'm going to start sharing my screen and we'll go from there.
So the first part we're going to go through, I'm going to have a slide deck. You can find the slide deck if you want to along with all the corresponding materials at bit.ly slash rmdmarvel. I love this kind of Captain Marvel movies. They're kind of built the idea around some of that. There's just some little images and kind of playing around with that idea. So the concept for today is we're going to go going higher, further, faster with Marvelous R Markdown. R Markdown is amazing. It's one of my favorite R packages, one of my favorite data products, one of my favorite things for just doing things in R and other programming languages. I'll also be working inside RStudio primarily. So you might see me log into RStudio here. I want to be very clear that everything I'm showing today up until the very, very end of the presentation can be done in R Studio Desktop or RStudio Server or RStudio Workbench. So there's really not anything here that's proprietary per se. The vast majority of this is open source R Markdown, which is amazing.
You can be very productive in your school, in your enterprise, as your hobby without really having to go and buy anything. You do want to go a bit further with RStudio Connect. I'll talk about that at the very end, but that's a small component of today's presentation. So let me go ahead and jump into the presentation. The kind of idea here, again, like I mentioned with Captain Marvel, is every heroine story has kind of three core acts. And just like that, we'll kind of go through some of that today. Act one is the story about our heroine is set up. Act two, some type of complication arises that they have to face. And act three is the heroine finds resolution, defeats the bad guy, wins the day. So for us, we're going to be talking about the tool, here's our Markdown, here's some problems, and here's some solutions you can do with them. Basically, some workflows you can use to solve problems with R Markdown.
R Markdown as a taxonomy
The way I like to think about R Markdown is that it's a lot more than just, you know, literate programming, although that's a huge component. R Markdown as a taxonomy can do many different things. It can be an environment where you're writing code, and writing text, and creating graphics, and creating statistical models, or data science, or machine learning. But it can also just be an end result as a data product. You can create something like this slide deck I'm presenting, which was made with R Markdown. You can use it as a control document to kind of control your code flow, and how you organize your projects, and bring different snippets of code together. And lastly, you can also use it for templating. So basically, leveling up your skills, and taking one thing and turning it into 100. Or taking one example, and adjusting it, and recreating it without having to rewrite all the code.
So we'll be going into all four of those different taxonomies today.
Literate programming
The first one, and I think the obviously one of the core workflows that you're going to do in R Markdown, is literate programming. The goal here is that you're going to capture your code, text, or comments, and your output in a single document. So you have essentially like this reproducible workflow of capturing your code, along with the output, along with any kind of comments about what the code is doing, or the outputs that you're seeing, all together. So you can share one document, or one report with someone if you wanted to do that. But you can also reproduce it, because you have the source code. The idea of literate programming has been around for a long time. Donald Knuth has this nice quote about literate programming as a programming paradigm. And the explanation of it is that it's logic in a natural language, such as English, interspersed with snippets of macros and traditional source code, from which the compilable source code can be generated.
Now when we think about source code in R, we have code chunks. So you have these little portions here, where you might recognize some of these, your favorite ggplot, some dplyr to filter a data set. But then with R Markdown, you can also intersperse actual text, you know, write about it, just as you would in a word processor. But now you get the benefit of doing code and text together. The other component I just want to bring up here is that there is the YAML header, which allows you to define certain metadata. So up here at the top, you can say, I want my output to be an HTML document. So this will, when it's rendered, when you finish it and you click render, it will actually create an HTML object that you can open up in a web browser. And you can switch this out to do Schrodinger or any other type of things or presentation like I'm doing today.
Visual R Markdown editor
Now going a step further beyond just that plain text, visual R Markdown was introduced in RStudio 1.4. So this has been around for six or seven months, but there's still lots of people who may not have heard about it. So I wanted to cover it today. You can essentially think of this as not only do you have the ability to look at the source code and the raw Markdown, you can also view it in a way where it shows you the actual rendered outputs. So when you create a table, it shows you a table. When you include a graphic, it shows you the graphic. You don't just have to believe that, okay, this code should bring in this image. It will actually do that live inside RStudio. In addition to that, it can do things with LaTeX or with real-time spell checking or all the different source code that you still want to be using. And you get a nice header up here that allows you to add things like bold, italics, cross-throughs, bullet points, tables, all those things with insertion. But it still allows you to do that with code and actually adds the code into it. I'll be walking through this in a second here live. So this may seem like, oh, this seems really cool, but we'll see it here in a second.
And then the last part is that R Markdown and literate programming is not just for R. You can do things like include Python via reticulate. You can use SQL inside code chunks to actually write raw SQL code. You can include CSS or JavaScript for some of your front-end development work. And you can include other things for bash, RCPP, SAM, and a lot of other different languages. So altogether, Knitter provides kind of interfaces to 52 possible languages. So you can do a lot in R Markdown, even though a lot of what I'll be showing today will be focused on R.
Live coding: visual Markdown editor in RStudio
So with that, let's hop over into RStudio. I'm working inside the RStudio team evaluation. Again, this is not necessary. It's just a reproducible environment I can use. So I'm actually logged into an RStudio Workbench session. This might look a bit different initially from what you're used to in using RStudio on, say, your desktop, but the workflows are essentially identical. Once I log into RStudio, I can hop into there and open up some stuff I was working on over the past few days and week, and we can go into some live coding of literate programming.
I'm going to be bouncing back and forth between the kind of source document editing I'm doing here and the live coding and back to the presentation. So stick with me, ask questions if they come up, and I look forward to kind of learning with you as we go along. So there's a lot going on in here. So I'm going to close down some objects. But in reality, we're just inside the RStudio environment.
So again, this will work just the same on RStudio desktop as you would inside RStudio Workbench or Server Pro or Server. The first one I'm going to be doing is the visual editor. So if you, again, want to go to bit.ly slash rmdmarble, you can actually open up the same files I'm working on.
The first one I'm going to use is this visual RMD file. So this file will look pretty similar to any R Markdown document you've seen before. There's a YAML header, there's some code chunks, there's a bunch of text, there's a table here, there's some images, all sorts of things going on. If I want to switch over into visual editor mode, I can click on the visual editor button right here. So this button will switch me to the visual Markdown editor. Once I click that, it'll reload the screen and will then convert what I'm seeing on the page into the actual represented output. So now rather than, you know, three pound signs and intro, it actually creates a level three header. All of my links get turned into hyperlinks. My code chunks get a gray background. I can still, you know, execute them. I can still run tidyverse and load the Palmer Penguins library. But I don't have kind of all the raw text around it. It will load tables and I can adjust the size of those tables. So we can resize this table real quick. We can move this over. So now we have a nice table. So that large represented table that I have here with embedded hyperlinks is now a visual table. And it's got some included graphics. Basically it's just walking you through how to use visual R Markdown. And there's a lot of cool things you can do with visual R Markdown.
What might be more useful is like jumping into an actual code example as opposed to kind of a demo of what visual Markdown does. So if we go to the Penguins folder, we've got a couple different documents in here. I'm going to start with the Penguin report detail. And again, I'm back into the plain text version. So you can see it still has loaded some of the graphics. There's some initial exploration here. And what I want to do is walk through this as a kind of literate program example. So we're going to move into visual Markdown mode. So again, I'll click the visual Markdown button. And now we have the formatted text along with my code chunks. We're going to use a couple libraries. So I'm going to load Tidyverse, Polymer Penguins, Broom, Skimmer, and the Bootstrap lib package. I've got a couple different documents here talking about what literate programming is, some initial exploration that we've used for how to use Skimmer, some examples of inline code chunks.
And what we're going to do is do a quick skim of these data. So if you're not familiar with the Polymer Penguins data set, it's basically a relatively small data set, about 344 rows. And it includes three different species of penguins for both male and female. This is a nice alternative to say the iris data set. So you can use it to replace some of that into workflows. And Skimmer is just showing us what are the different variables in this. So there's a lot of information about the bill length, basically how long their beak is, as well as the bill depth, how broad it is. And then their flipper length, or how long their arms are, their body weight, their body mass, and the year that this was observed. All the data was collected in 2008. And a big thanks to Allison Horson and Allison Hill for putting together this data set into a nice R package with a wonderful website. So now with basically three or four lines of code, is able to get all this metadata about this data set. So there's a little bit of missing data, the average grouped by species, and bill length, and all the different variables, the standard deviation, and a histogram of what that data set looks like.
Now you might be saying, well, why didn't I just use dplyr? And you can still do that. So I'm inside in the visual editor. I can say, OK, we're also going to look at some specific statistics. We'll split the groups by species and look at which ones are the lightest and which ones have the shortest flippers. Oh, looks like I made a mistake and RStudio is catching that I misspelled lightest. So I will correct that. Thank you for the warning there. And now I'll run this code chunk and we'll now get our dplyr output. So we've grouped by species and sex. We've summarized, got the weight of the animals, the flipper length of the animals, and we've arranged by descending weight. So what we observe here is that the Adelaide penguins look to be the lightest, although there is some NAs in the sex. So some of the missing data there is in the sex column.
And the males are about equivalent to the chinstrap males, but the females are much lighter than the rest of the other ones. OK, so it looks like the Adelaide are the lightest penguin. I can continue going through my code and I can filter out the is NAs and I can find some that actually have this. If I want to make it where there aren't any NAs in the sex, I can also just change that to eliminate the exclamation point here does the opposite. So it does find no NAs in the data set. So we've only got about 11 rows of the 340-ish that are missing data. But let's go ahead and make sure that we're not missing any animals that are missing body weight. So we'll find the smaller data set.
So I'll kind of go through this. And really, the idea here is that we've got a lot of text. We've got inner snippets of code. We've got graphics that are going to show up in line. And we can create even fancier graphics or split it out by specific portions. Nice graphics here. And then we can find a small linear model between the body mass and the flipper length. There's a very strong linear relationship between how big the animal is and how long its flippers are. This might seem silly. We're kind of sticking to a fun data set because I don't want us to worry too much about what the data is as opposed to the techniques we're using.
Really, what we've done here for a few minutes is just walk through a live coding example. And it's really just me running code. But you can see that if I gave this to a colleague where I was looking at this, this is nice to read through. This reads almost like a report already, even though I'm able to edit it and kind of change things as I go. So, you get this experience of kind of a word editor or a word processor with the ability to run that code. And that's really what the beauty of literate programming is, is mixing in the comments or the things you're writing along with the code you're writing.
The other part I want to show, if we go back to the visual editor, is we can also do this same workflow with reticulate. And I can actually use some Python. So, I'm going to, again, switch to visual editor mode and just show you that it does still work for Python and in R.
So, we'll load these libraries. I've loaded reticulate to allow me to use Python on the back end. And then I can import pandas and get the penguins data set into the pandas object now.
If I look at the environment, I have the ability to switch between R and Python and see those different objects. I'm in the Python environment now and I can see the data set that I brought in. So, you can see the same one. You'll notice that Python refers to NAs or missing data as man versus R is going to refer to those as NAs. So, small difference, but it does translate back and forth nicely.
So, let's close that down. And then since I kind of showed you the workflow of doing this live, let's just knit the document. So, we'll take the reticulate document I have that has a little bit of Python. It does some data cleaning in pandas as opposed to dplyr. And we can show the final output here in the browser. So, this is very important penguin analysis that we're doing here. So, again, we're pulling in pandas. Instead of skimr, we're using the describe function from pandas and we're looking at a few different things by the species. This is done in Python. And then we'll do some group by summaries with pandas again. So, again, grouping by species and sex, getting some outputs, and then showing the data set when we drop some NAs and filter to just species equal to Adelaide. We can then take that Python object and pipe it back into ggplot. I'm much more comfortable in ggplot than I am in matplotlib or other libraries in Python. So, I just moved it back in. But really just the idea of, like, if you know a little bit of R and know a little bit of Python, you can work with them in the same document and kind of use that for learning or use it for some of the reporting or other kind of scientific computing that you're doing.
Q&A and RStudio tips
Cool. So, we spent quite a bit of time on literate programming. We're going to go back into the presentation and talk about our next taxonomy. Also, take a breath and look at some of the questions that are coming in.
Question number one was, has anyone found a good method of real-time collaboration on R Markdown in a similar way as Google Docs? That's a great question. Obviously, you could do something that's more asynchronous by checking into something like version control. So, just as I was saying with using the code rmdmarvel, if you go to say, like, GitHub, you can literally use the things that I'm working on and edit those. So, I was just in the visual editor. And then the one I was working on was the reticulate slash doc. So, now you could add some edits to this. You could pull it in and work on it. That would be asynchronous. An alternative would be that RStudio Workbench actually allows you to do live editing of the same document with project sharing. So, that is a professional product that we offer. But that is an option if you're worried about, like, collaborating at work and needing to work remotely, but still share documents.
You could also just have a shared drive. Like, if you're talking about Google, you could upload documents, edit them, and move them back and forth. I still think that version control is probably the best idea for just, like, being able to comment on something, make edits, and then try and talk through that process.
One other thing, how do you have that many panes? Let's talk about, go back into this for a second. So, RStudio 1.4 introduced not only the visual editor, which, again, is this button that allows you to show the kind of rendered output, it also added support for the multi-panes. So, if I go to tools and go to global options, pane layout, I can add new source columns. So, you can see I have my four typical panes, but then I have an additional source column. And if I apply this and click okay, go back in here and drag this over, I now have the ability to work on a single document in the middle and also have a more basic report off to the side. So, I can edit, like, two files at the same time. You're not editing the same file, but two different files. I use this quite a bit for doing things like Shiny, where you might be writing essentially, like, the front-end portion, the user interface, and the back-end server component in separate files and bringing them both in together. So, that's a good option.
Data products with R Markdown
But let's hop back into the presentation real quick. So, we talked about literate programming for a while. The next kind of taxonomy of using R Markdown is the idea of a data product. And here we're using R Markdown to, and using R to generate a final output for consumption. So, yes, you know, you want to be reproducible. Yes, you want to include code. But here, you're mostly concerned with I want to create something that I'm going to give to someone to help them make a decision, convince them, or just report on something. Like, here's the daily report, or here's a machine learning pipeline I ran with tiny models and fit all these different parameters, did hyperparameter tuning, and here's the final model and its fit, but with all the code available.
There's a ton of different data products you can create with R Markdown. You can create reports. So, static HTML reports, like I was just showing when we rendered that document. PDFs, you can save out so they could, you know, share them via email or just have something you can have offline. Rich text formats, GitHub documents, or even Word documents. Presentations, just like this one is. This one was created in Schrodingen. So, that is a R Markdown package using reveal.js, or remark.js, I'm sorry. You can create PowerPoint presentations. You can create other, kind of, more native reveal.js presentations, Beamer for LaTeX. You can create full-blown dashboards with flexdashboard that can be either static or you can integrate Shiny and make them interactive. Entire websites. So, some of y'all may actually have R Markdown blogs. I personally use DeCille for my personal blog, and BlogDown is a great option for a lot of power and uses Hugo on the back end to convert Markdown and R Markdown into complex, sophisticated websites.
You can write books, beautiful books that, you know, people have literally published. You think of, like, R for Data Science, a book by Hadley Wickham and Garrett Grohlman. That was written with BookDown. You can actually look at it online in the BookDown format. And lastly, one of the things I'm really excited about for R Markdown and data products are HTML widgets. You may have been exposed to DT, or the JavaScript Data Table Library, or Reactable, which is similar, and creates interactive tables in R that use JavaScript on the back end. So, without even having to use Shiny or a server, you can have the ability to sort, rearrange, or change the data you're seeing on the screen all at once. And there's Plotly for graphics, crosstalk for interaction. We'll dive into a little bit of that.
But here, you're mostly concerned with I want to create something that I'm going to give to someone to help them make a decision, convince them, or just report on something.
So, we're going to hop back into the environment here. So, we'll go back into my Penguin project. I'm, again, going to push this extra pane over because I want to zoom in a little bit more on this one. And we're going to go into Penguin project and look at data products.
So, the first one we're going to be looking at is, I was talking about different output formats. So, Distill being the ability to create a web page in R. So, let's close down some of these. We'll save that. Clean up my environment a little bit. I got a lot going on here, y'all. So, close this one, close the readme, close down some whiskers, the multi-plot. We've got a lot of exciting things today, and I don't want to get to them too fast. So, we're going to close down all these. And then I'm going to pull this one over. This has my Penguin Distill, which, again, is Penguin-Distill in O2 data products. This may look almost the same as what you were looking at before with your visual R Markdown. It's essentially the same report or similar, but when I knit it or render it, that's when it gets turned into the new format.
So, with the Visual Markdown Editor, you still get all this nice formatting, but when I actually click knit and actually ask R in R Markdown to render it into the new format, it will render it out as something else. So, in this case, because I have it set as Distill, so you can see output Distill dash, sorry, Distill colon colon Distill article, it's going to create an actual Distill article instead of a basic HTML doc.
So, here's Penguin's Distill. This looks quite a bit different. I love that it has this floating table of contents, that it has some information about when it was published, who the author is. It's more of like scientific writing native to web. So, this is an HTML document, but it is really like how to do scientific writing. And again, you still get all the niceties and kind of the core R Markdown work. So, this is still the same code I was using, but I was able to generate a different output simply by changing the R Markdown YAML. So, still a lot of the great things, but it's got really, really nice headers where I can grab this specific link to the modeling section and share that link, or I can look at my different models that I've chosen at the bottom and where there are squares at the very bottom here, I can do the wrap up, and it gives me this nice table of contents where I can jump back and forth between everything. So, I really like Distill. That's a good option if you're trying to create a personal website or some scientific articles.
So, let's get back into here. I'm going to click on this, drag this one all the way over, and the next one we're going to do is a Schrodingen presentation. So, again, the data product here is more of a presentation. So, just like the presentation I'm showing you, this one was created with R Markdown. I literally wrote a bunch of R Markdown code to generate the presentation that we're going through. This looks pretty similar to what I was doing before in terms of it's got really the same code chunks. The specialness here is that instead to kind of tell this presentation format, this is a new slide, I use three dashes to say go to the next slide, go to the next slide for each of these different sections. So, each one is a slide break, but I can still use all of essentially the same code I was using.
Now, this really makes more sense when, again, I render it out. So, if I knit this document or render the R Markdown into a Schrodingen presentation, I can then open that document, give me one second to pull it over, and then now we have that same kind of report I was talking about as a live presentation in a few seconds. So, here's the information we're looking at. Here's some penguins. We're looking at their bill length, their bill depth, their body mass, their flipper length, all this fun little data points. We're talking about literate programming. Here are the specific statistics I'm interested in. So, grouping the data by species and sex and getting their body weight and their flipper length. I can clean up the data. There were some NAs, and we dropped all those with NA omit. And now let's get into the plotting section. So, we're going to show a quick distribution of the data. We'll have the example of the live code up here, and then we'll show a linear model and a scatter plot. This is, again, the same GD plot that I had before. I didn't have to adjust anything. And then we'll move on to the modeling section. So, now we have all of our models I'm fitting. I've got a list of objects of some different formulas, and then we're going to summarize those into different models, broom to clean them up. And now I have a nice table with the GT package of what are my different model formulas I was using. So, looking at flipper length by body mass, the R squared, the P values, the sigma, the statistics about these. So, obviously, I'm flying through this portion, but the idea here is that with literally, like, no change to the underlying code, I'm able to get all of the different things into this object. So, like, get them into a presentation.
flexdashboard and Shiny
Yeah. There's one more example I'm going to go through about data products, and then we're going to talk a little bit more in the presentation. So, number one, a flexdashboard is a way to create dashboards in R. What I can do is actually run this document. I'm running the document because it has a shiny runtime. Shiny is not required for flexdashboard, but does give it a lot of extra power in terms of now you can have a server component on the back end and execute something.
So, the basic idea of this flexdashboard is it separates different components into portions. So, I have kind of a tab here for miles per gallon weight, a tab here for miles per gallon cylinders, and then a table about them. What shiny is doing is giving me linked brushing, or the ability to select specific objects or observations and then show something different. So, by using this as a control environment, I'm able to just limit it to specific miles per gallon, a specific weight combination, or even just one data point. Or I can get a whole section, zoom in on those, and then adjust both the table and the graphics here. This is done with shiny,
and it's taken literally verbatim from a flex dashboard site. So, you can actually recreate this or the source code that they share is embedded inside of it. The shiny runtime might, you know, that's very exciting, but that does require you to manage a shiny server or RStudio Connect on the back end. So, an alternative, because you're working on R Markdown, is something like crosstalk. And what crosstalk does is gives you the ability to cross communicate or crosstalk between different HTML widgets. An HTML widget might be a plotly graphic, or a DT data table, or a reactable table, or all sorts of different HTML widgets. The idea is that those are using JavaScript, that you're writing via R, and they can still communicate with each other.
So, there was a question in the chat, does knit mean render or essentially an enter based function? What knit for render means is take the document, run it from the top to the bottom in a linear fashion, and create the output format. There's all sorts of side effects that are good in terms of you could write out different files. The idea is render is like run the entire document and render the output, or knit the document and render the output. Those are interchangeable. You can use the RStudio knit button, or if you're doing it from the R console, you could do R Markdown render, and just pass the file name to it. So, it's not required to use inside RStudio, but we do provide a knit button for it. So, with that, let's knit the document real quick, and we will wait for it to render. So, it's going to go through and reading the lines and pulling in the code, and it's going to generate an output for us to walk through.
While that's rendering, I'm going to look at some of the questions in the chat.
There's a great question about the jobs pane that I want to talk to in a second. I'm making Markdown usable. Okay. And this one was output to Reactable. So, let's do that in a web browser. That's not the one. That's exciting, though. Let's do crosstalk HTML. So, the output that we created was a crosstalk document. Again, this might look like the exact same plot we've been creating for a little bit while, or for a little while, flipper length and body mass. So, there's a linear relationship between that.
But the beauty here is that with crosstalk, I have an interactive graphic in terms of this here, all these little points I'm hovering over, the hover text comes in for free. You get the hover text in all these different documents. With a table, you have the ability to go paginated or sort by species, sort by sex, sort by any column. So, you have interactive components, interactive graphics, interactive tables, all of this available for free and all this able to be used within your enterprise, within your hobby, within your workspace.
What crosstalk is doing is giving you some of these filters. So, this may look exactly like Shiny, but there is no Shiny server on the back end. This is all done in the browser on your local machine. So, I can filter this data set to only show female penguins. So, now the only sex in the table is female, and all the observations we're seeing up here are female only. I can show just the males and do the same thing. I can show the males and the females together. Great. I can filter the body mass to show only the lightest penguins, and we can kind of see the drop off of the Gentoo as we get to about 4,000 grams. There's not really any Gentoo penguins that are observed at that body weight. So, again, all of this is happening where I'm changing things here. It's affecting the plotly graphic. It's affecting the table, and they're communicating together to give you this output.
And again, the beauty of R Markdown and the beauty of crosstalk in this JavaScript library is you don't have to manage a server. You could literally publish this to GitHub or Netlify or RStudio Connect or just take the file and literally like deliver it to someone else by email if you wanted to or by shared drive. They can open it and get this interactivity that you're expecting.
And again, the beauty of R Markdown and the beauty of crosstalk in this JavaScript library is you don't have to manage a server. You could literally publish this to GitHub or Netlify or RStudio Connect or just take the file and literally like deliver it to someone else by email if you wanted to or by shared drive.
So, all of those amazing things you can do with crosstalk and R Markdown. You can still leverage Shiny on top of that if you wanted to to get even more power or to actually execute new R code. You are limited to what these libraries can do in JavaScript, but if you add Shiny, then anything you can do in R can be added into the object as well.
The jobs panel and background rendering
So, back into here, there was a great question in the chat about the jobs panel, and part of the idea is that could you execute R Markdown renders as a background job? The jobs panel might be new to a lot of folks. This is, again, available in the RStudio desktop, the local IDE. It's a free thing. It's just available. You could render anything R Markdown if you wanted to as a background job. You would just have an R script that literally contained R Markdown render and then whatever the R Markdown document you wanted to do. So, you could parallelize some work if you wanted to, like, you know, render this one. I know it's going to take a while. Also, render this one, and then that leaves you free to continue using the R console to do other things.
So, these jobs are still executed in your local environment, but behind the scenes, so they don't, you know, use the same R source that you're using, you do them as a background or an alternative R environment. So, yeah. So, the jobs panel is amazing. That was also introduced relatively recently. You can use it. What I use it for a lot is for long-running computation, like parameter tuning or grid search, where you're going through a lot of different things all at once. It could take 30 minutes or 45 minutes or even longer in some cases. I don't want to lose everything, like, lose the ability to do my console for 30 minutes.
So, when I was watching Slice, I was really hoping a lot of people can be using background jobs so they can continue, like, doing graphics in the R console while the code is fitting in the back end. That would be a cool example. Let's hop back into the presentation. We talked about quite a few of these different data products. We've got about 25, 30 minutes left, so I want to make sure that we get through everything.
Answering chat questions
For the table column width, the basic idea for the visual editor is when you, you know, bring in a table, create a table that has default widths, those will adjust to the size of the contents. There are some cases where if you have, like, really, really long content, it can create a table that you need to adjust, and you can just drag it over with your mouse to adjust the size of the column.
For Schrodingen and all the colors and layout styles, I highly recommend the Schrodingen Themer package by Derek and Dewey. That is an amazing package that allows you to write full themes for Schrodingen, and you can get, you know, beautiful colors and specific, you know, fonts or CSS embedded in there as well to make it custom.
For GT summary tables in R Markdown, I use GT all the time inside R Markdown. I don't think there's any known issues with GT summary, but the idea would be is that if you use GT summary within R Markdown, you can just render it out and get the GT summary in there as well.
A great question here. Are all these features you're showing in RStudio free? Yes. Everything I'm talking about right now is free. These are open source packages. Some of them are community based. Some of them are studio based. This is the beauty of open source and our community and the JavaScript community and the Python community is that all these different components can be connected together, kind of, you know, revamped or integrated, and you get this amazing power within free and open source tools.
Last question I'll answer here is you could use different YAMLs. You can, like, render one as a Schrodingen, one as a Distil. The one difference is that Schrodingen has a very different internal syntax. Those three dashes are going to create new slides in Schrodingen, but they will create a horizontal line in Distil or R Markdown. So, while you could have one document literally generate two or five different types of output, you may have to change some of the skeleton of it, not the code, but the skeleton of, like, how it presents. And the last one here, when you do render when the document is in flexdashboard, you just render it just as you would with anything else. The difference is if you're using Shiny, you're actually going to run the document. It essentially treats it as pre-rendered. So, it renders the flexdashboard, then brings in the Shiny component. If you don't have Shiny there, and you're just doing static or HTML widgets like crosstalk and flexdashboard, then you can just render it like anything else.
So, we've talked quite a bit about all that. Thank you for kind of sticking with me through a quick run through a bunch of data products.
Control documents
The next taxonomy I'd like to cover is the idea of a control document. So, this is kind of a step beyond the classical ones. The first two people have probably done a lot of that. Control documents are some that I had not done as much of before I'd done some research. So, the goal here is to modularize your data science tasks and use R Markdown to control your code flow. That seems kind of clinical in terms of, like, code flow, data science tasks, like, what are we talking about here? Part of what we're talking about here is, you know, taking something and generating something new with it. So, parameters in R Markdown can be added to the YAML header with the params, colon, and then whatever you want the object to be named. So, in this case, like, species equal to Adelaide. When I render this document, it will run the code in here, but then it will pull in whatever the parameter is. So, without changing the body code, I can change what the actual report does. So, I can say, for the Adelaide penguins, generate this, you know, these different filters and this different graphic. And I can just change this one line of code in terms of this parameter, and it will generate an entirely new report or entirely new document that is specific to that. You can have multiple parameters. I'm just showing the bare bones example of one parameter with one component. You could have five or six different parameters or more, and you could have multiple different things within that parameter. So, you could have, like, a string or a vector inside there and kind of run through all the different ones. The idea is that you're just, without having to change all the code and rewrite ten different reports, you can generate ten reports just by changing the parameter ten times. So, very powerful.
You can also reference .R files. So, for a lot of folks, you're like, eh, you know, like, R Markdown, it feels like a lot of, you know, there's a lot of different power there, but, you know, I have to write all these different things. I'm just going to start in a .R file. You can use and reference external .R files a couple of different ways. So, you could always just source an internal R file and just read in things from an external file, but the NIDR read chunk option kind of gives you the best of both worlds. Here you might see that I have code chunks that are named, in terms of this is smaller penguins and this is plot penguins, but none of, there's no code in there.
There's nothing in here. And that's because with read chunk, I'm actually able to read in from a .R file specific chunks. So, this colon, colon, sorry, pound sign, pound sign, and four dashes essentially creates a chunk label. So, even though I'm inside .R files, R Markdown can understand this descriptor and say, okay, everything inside here is the smaller penguins chunk. Everything inside here is the plot dash penguins chunk. So, I can actually write things in a .R file, reference them in multiple different .R Markdowns. You can imagine I have a shringen, I have PDF, I have Word doc and HTML, all those could reference .R files so that you're just writing the components in R Markdown that are specific to R Markdown, like how to create the presentation. And you can source some of the other more complex code you're writing in R from the .R file. Just an option, not mandatory, but definitely possible.
Child documents and conditional reports
The other idea is child documents. So, I could have a core kind of parent document here that is just an HTML document. It's got a couple library calls in terms of loading Tidyverse and Polymer Penguins. And then just like before with the read chunk, I have a blank chunk here. There's no code in it, but it's saying for this chunk, read in the child report, Adelaide report, .R Markdown. And that will take everything in this. So, the smaller, this code chunk, this text, this code chunk, and embed it into this portion. So, essentially you wrote all this and put it into the parent document. Again, the idea of like you're able to build up different components and reuse parts from different documents into kind of a parent or a core document that you want to reference that in. So, again, if you're playing around with different output formats, you could always just, you know, write a document and change the output format. But sometimes you may want to actually leverage a specific report that gets brought in.
This becomes even more powerful if you think of like conditionally adding a report. So, for my example, it's the same report that we had before. So, we're bringing in this child report. The parent report now has a conditional statement. Essentially, if this object is Chinstrap or if it's Adelaide, then bring in this report. So, that will basically say as long as this means Chinstrap or this means Adelaide, then render the Adelaide report and bring it in. The better example and the kind of more complex example is if a criteria is matched. So, if values are above or below a certain value that is concerning, then bring in all this other code, run it, and generate the kind of worrisome report there that you want to catch up to. Like, you know, the data is way off from what the norm is. Oh, my gosh, what's going on? Add all this different thing to check the data quality that you don't necessarily aren't doing all the time, but you're doing it for here. That being said, please check your data and check data quality. But just as an example, you can do these kind of if, else, or conditional statements inside the child document. Another idea of like parent and child documents is blastula.
Blastula can be used with things like Gmail or you can use it with RStudio Connect to send emails. The core idea, and there's a bit more code here, we're loading some libraries, we're creating some graphics, and then we have this render email portion. It will basically take a Blastula written email. So, you can see that this Penguin email, the output is Blastula, Blastula email, and render that as an HTML email and then send it. The example I'm using here is rendering it and sending it via RStudio Connect. You can also render it via SMTP, which is a protocol that like Gmail uses. So, again, Connect is not required to do this. It's a nice integration, but you can do this for free with your SMTP style servers. These emails can intrude arbitrary R output like ggplot or even tables or images of tables. You can basically include a lot of different things inside an email that you're sending out to your colleagues or to yourself. I use these a lot for do this thing and then tell me what the output is in a summary.
Templating in R Markdown
So, we covered those and most of those kind of, in my mind, the code is covered here in terms of all we're doing is pulling in code and rendering it. So, I'm not going to go through the live examples. I did include an entire section inside the Penguin project. So, Control Documents has Blastula emails, it has emailers, params, external files, using child, using traditional child. You're welcome to walk through those. Again, at bit.ly, rmdmarvel. But because it's just rendering the same document over and over, I'm going to spend the next 10 or 15 minutes talking about our next topic, which is going to be templating. I really love the idea of templating as well. So, for templating, a lot of people think of like taking one thing and making it other things or taking one thing and changing something about it to make it different. So, here, Captain Marvel is working with her friend's child and changing the look of her outfit.
So, that's really cool. You could change, you know, what an R Markdown appearance looks like with a different theme or different CSS. But more of what we're talking about is don't repeat yourself, generate input templates or output documents from code. So, if you think about parameters, that's something we used before was, you know, defining a parameter, setting it as a species equal to Adelaide, and then we generate this report. Obviously, you could go into the R Markdown, delete this, type out, you know, chinstrap or Gentoo or one of the other species and click render, or you could do it from the command line or the R console. So, with R Markdown render, you can take this report, so the penguin.rmarkdown, and define the parameter as something else. So, here, a list of species equals to Gentoo instead of Adelaide, and now this will generate that report with code with that new parameter. So, now you've generated two reports with the same report, essentially. So, two different outputs from the same input.
A more interesting example in my mind is multi-render, where you actually take all the different possibilities of the parameter and generate all of them. So, here, I'm wrapping R Markdown render into my own render function so that I pass in penguin to my render function. It takes the same report. It replaces the species with whatever the penguin I put in, and then it creates an output file with the name of that penguin-report-html. So, now I can find all the distinct penguin species. I can pull that column out, and then I can render that with per walk. So, basically, it goes through each of the different possibilities and generates a new report for all of those. So, now I have an Adelaide report, a chinstrap, and a Gentoo report all from one set of starting code. You can imagine that this could be something like, I'm changing the year, or changing the month, or changing the day to generate this report data. Or, for like a modeling task, I'm changing hyperparameters or the different modeling function or different data set and generating an entire report on it. So, you can do a lot of different things with parameters and looping through different parameters.
Now, the other idea is rather than generating 10 reports out, you might want to generate multiple things in one report. So, here, I'm doing something similar, but all within one report. So, I'm sourcing an external file. This is multi-plot, which is an R function that basically outputs markdown text. It outputs a plot and prints it, and then adds some blank spacing. And then I have a loop here. So, this is a code chunk called loop output. I'm using results as is, so it just pastes the literal output here of what this R code generates. So, it actually outputs essentially text. I'll take the penguins data set, find the distinct species, pull the species, and then walk through, again with per, this function three times. What that does is generate three different versions of the same text and the same graphic, but nuanced or kind of specific to whatever the input was, whatever the penguin that we're generating was.
So, let's walk through that one real quick. So, we're in templating. I'm going to show a couple things. So, penguin params. I'm going to pull this over. Again, the species is Adelaide. So, I can knit this document. Pardon me. Let's let that document render or knit, and then I'm going to pull it into the browser. So, this is a pretty bare bones report, but you can see 193 are classified as Adelaide. The distribution of Adelaide penguins are below, and there's a big chunk of them that are Adelaide. We go in here and change this to the chin strap. Chin strap. I can, again, knit that report and get the essentially new one out. So, if I refresh this, it should be chin strap, I think. Let's see if we can, yep. There's chin strap, chin strap, and now we have 276 penguins instead of 344. So, I can do it that way. I can do it with knit with parameters. So, if you just click up here on knit and go down to knit with parameters, it will pull up like a kind of Shiny component where I can change this and do Gen 2. So, now we can knit that to Gen 2. So, it's going to do the same thing and render a new report for me with Gen 2. So, here's the report we're looking at. Pull it over there.
So, that's possible. A couple different options. You can knit and just change it. You can knit with parameters, but the more powerful part that I like is the multi-plot or render all. So, render all is the idea of like rather than manually changing things or going through all the different options, I can, again, use my render function. If I go up here and get all those, my render function, here we go. So, this will render the specific documents, but I want to render all of them together. Again, this is the same thing I showed in the presentation of here's the templates and penguin params, and then we're going to show the species equals chinstrap. That's fine. With the penguin names, we're going to pull those out. What this basically gives us is the three different penguin names, and then we're going to walk through those with the per walk render function. To just prove to you that that actually happened, I got some code here to show you that this was run at 3.52, whatever the time is on the server, on August 26, and it happened about a second later was when they were actually generated. So, these reports were generated just now, and it gave us the Adelaide report, the chinstrap report, and the Gentoo report. So, that's super powerful, and I think that's a really, really cool idea.
So, these reports were generated just now, and it gave us the Adelaide report, the chinstrap report, and the Gentoo report. So, that's super powerful, and I think that's a really, really cool idea.
The loop within a doc R Markdown is also really, really fun. So, here, this is the one that's using the reports up here in terms of it's going to walk through the multi-plot that I've already defined, and it's going to create three different outputs in the same document. So, let's knit that and see what it looks like. When we render this, it's actually reporting out as is, and then it's going to generate this loop within the doc HTML. Let's take a look at it. So, for Adelaide, it gives you a level three header, and it gives you these observations. So, here's 151 observations of Adelaide penguins, and the flipper length is 190. For Gentoo, it's got a different graphic and different numbers, and then for chinstrap, a different graphic and different numbers. So, from one dot R file, you're able to generate multiple outputs within a single document. So, again, a slightly different idea.
Whisker vs glue for templating
The last idea I'll talk about is whisker versus glue. So, the way I like to think about this is one versus two, if you're thinking about these parameters on the outside of these brackets. Glue is logic templating in terms of you can take a string, put anything you want with valid R code inside these brackets, and it will interpret that and execute it inside that context. So, very, very cool, very strong package. Whisker is logic list templating, meaning you have to define the object at a time and then pull it in. It also uses two brackets instead of one. The reason why it's logic list is that it's really thinking of it just as text as opposed to code up here. So, if you tried to do the same number of row of empty cars, it will just print a blank there because it can't interpret that, so it just returns blank. Where whisker is very powerful is the idea of generating actual dot RMD or dot MD files, like basically generating new input files or text files from an input file. That kind of blew my mind the first time I thought about it, so let's walk through an example real quick. If I have this report, so this is an actual R Markdown document, but you can see I've got these double brackets in a few different places, so the name of the penguin, the name of the species, and some long pros here.
Now, you could think, well, I could just replace this with params, but the beauty is when you use whisker to fill in this document, which you see on the right, so Adelaide penguin, Adelaide, and then this long prose about them, it will actually allow you to still work with the document. It's still a raw dot RMD file, so that's really powerful and you can continue working with it. So, this is what that function looks like that I was using, use penguin template, which reads in this file, fills it with whisker, basically replaces all of the different observations with double brackets with species equal to Adelaide and this long prose and generates that output.
Sorry, let's do penguin whiskers, use penguin template. All right, so here we're going to define that function, species, long prose, and we're going to use this use penguin template. We've now filled the blank template with this really long text string and a bunch of other stuff, and now we can actually navigate and edit that file inside RStudio. So, now we have an R Markdown document that I can continue adding to. Here is more text, but I've programmatically filled it with different parameters of interest. So, there's certain times where this is amazingly powerful, there's certain times where you should probably just use params, but the idea of like, if you want to be able to continue editing it, like if you're generating a trending document and you put in all this code and fill in some parameters, but then continue editing the slides, this could be a really powerful option.
R Markdown with RStudio Connect
So, we've talked about all the different things you can do inside templating. The last component here, and we've only got a couple of minutes, I think that was part of the intention, is that all the things I've showed up to this point have literally been all the amazing things you can do with R Markdown for free and within your own kind of choices. This last component is a bit about R Markdown within RStudio Connect. So, RStudio Connect is a professional product from RStudio. It's a hosting and execution platform for Shiny, R Markdown, Plumber, as well as things like Jupyter, Flask, Dash, and Streamlit for our Python folks.
You can use it to execute or schedule R Markdown for basically anything. So, not only can you host things there, but you can actually have Connect re-render or re-execute this code in the future. So, you could provide parameterized R Markdown where someone can actually go through, change parameters, and re-render it without having to know anything about R. You could schedule ETL jobs and pull from SQL with dbplyr, APIs with Hater, or Spark with Sparkly R, and then bring those into R and do other things with them. Connect provides reports that actually have logging and history, so you can have multiple versions of the same report over time. You can schedule some of your long-running training steps that take three hours and have them run at three in the morning, so that when you come in in the morning at eight, or when you log in your computer, all that's been done overnight and you've got your batch scoring done and ready for you in the morning.
And then with Blastula that we mentioned earlier, you can actually create and send emails conditionally or on a schedule. So, here we've got it scheduled for 9.36 a.m. Central Standard Time. I want this report to run every day, and publish the output and send an email. We'll just, for one quick second, I'll show you what this looks like. I actually scheduled this report to run every hour for the past few hours. So, you can see I've got a couple emails here it's been sending me. So, we've got an actual Blastula email that has an attachment of a PDF, a CSV file, and a PowerPoint file. All this was generated with R Markdown. It gave me an embedded ggplot, an embedded ggplot, and an embedded table. And this was run with RStudio Connect over and over and over with different data and sending me these different parameters. So, this is the power of, like, all these things you learn are amazingly powerful in your local machine. If you want to go a step further and have, like, authentication for these documents you're sharing with an enterprise, or scheduling,
or some of these other things that are worth paying for, then you can look in RStudio Connect and do some of these amazing things. That being said, you can also send emails like this from Gmail or from an SMTP server, and you don't need RStudio Connect. But what RStudio Connect is providing is the scheduling, the authentication, the logging, the history, some of those things that a lot of our enterprise customers are concerned about.
So, that was a whirlwind tour. We got it done in exactly 60 minutes in this fun experiment we did together. So, thank you for tagging along with me, listening to me talk in my 200 words per minute voice. Thank you to Allison Hill for defining that. A bunch of different follow-up links. There's some articles that people in the community have written about how to use R Markdown to be very powerful in your enterprise. So, Emily Ritterer, Charlotte Gelfand have really great articles on this. I have one covering this same idea of, like, taxonomy of R Markdown. There's two entire textbooks about R Markdown.
The cookbook for different examples that may answer some of the questions that folks had in the chat that I didn't get to. And then definitive guidebook, which shows all the possibilities of what you can do with R Markdown. We also have a few different webinars that people in the community, again, have showed, like, here's how we're using R Markdown or other things within our enterprise or within our specific domain. So, maybe you come from the insurance or finance industry. This report talks about rethinking reporting with automation. Nice video from the community there. Using R to enhance clinical reporting within the life sciences industry. So, maybe you come from life sciences or healthcare. This has some clinical data and clinical applications. And one of my favorites that's a bit more general is avoid dashboard fatigue. A lot of that is talking about how to go beyond just creating these kind of dead dashboards and doing things like scheduling, doing things like creating rich outputs and different ways to engage with your users.
I know that Rob or whoever is working with me in the chat is also going to be dropping some links to some follow-up material. So, he will be dropping off a kind of summary of everything that talks about some of the packages that has links out to these other things I talked about. And if you want to look at the code I used and, you know, riff off of it or adapt off of it or just play with it by yourself, you can go to my GitHub at github.com slash jthomasmock slash penguin-project or bit.ly slash rmdmarvel. That's the short code and I will drop that in the chat again. That will take you, again, to the same page I'm on here with all the code. Oh, again, to the same page I'm on here with all the code. Oh, and I misspelled it. Apologies.
Bit.ly. So, let's try that again. See if we can get it rolling. There we go. So, my apologies. Correct link there. And you can have fun with it. And, again, I know that we covered a lot here. I try to be a bit more motivational with some of these things in terms of, like, here's the things you can do and then giving you examples to build off of. I find the way that I learn the best is from these projects or doing project-based learning where I can take something that I know is working in a minimal way and expand it to be useful for me in my job. Do something in a different way that is useful or a new way that I wasn't able to do it before. So, go out, have fun with our Markdown. You have all this amazing power available to you for free that you can rip off and change. So, go out there, use it, and have a good time. I'll stick around for a little bit and try to answer some more questions as they come in. But that is the end of the core presentation itself.
You have all this amazing power available to you for free that you can rip off and change. So, go out there, use it, and have a good time.
And thank you for tagging along. We are doing this as an experiment. So, if you could take some time and actually go through and fill out the Google form that was just dropped in the chat, please do that. That will help us understand, like, what other types of things y'all would like to see in the future, where we can make improvements, where I kind of slipped up, or where kind of things could be better. So, thank you all for attending. Thank you for your time today. And everything was fantastic, I think. So, thanks for your time. I'll try and answer a few of these different questions. Also, for anyone that's still here, this is Howard. This is the bonus Howard slide. It's almost the end of summer here in Texas. Not really, but this is my dog, Howard, who loves watermelon. So, that's something to take home and run with and have a good time with.
Answering audience questions
Let's do some of these questions. I think I answered the one about R Markdown Render and Flex Dashboard. But again, if you're using a static Flex Dashboard, you can just R Markdown Render it just as you would like. If you have a Shiny component, you will then run the document as a Shiny app, because you have to have that server component.
For parameters, how can we get a list of options with an API endpoint? That's really interesting. I assume that you could pull in something if you had like an API, and you were pulling in data with, say, like the HTTR package, and you could pull that in. I'd have to think about using API as a way to generate parameters, and I don't want to kind of speak off topic. So, I'll try and do something in a follow-up blog post for that, and we'll release that.
Is there a good way to output a specified set of dashboard views to a PDF? So, you can use the webshot2 package. I didn't have enough time to talk about that today, but the webshot2 package allows you to take screenshots of HTML and then embed them somewhere else. So, you can imagine that HTML is amazing. HTML is what I think you should be creating, because you can do so many different things with it and make it interactive. But sometimes people are like, I need a PDF, or I don't have internet access. I need to have this, or I want to print it out. A couple different use cases. With a PDF, you could actually do webshot2 and print different HTML views, like a Flex dashboard, to a PDF. There is a blog post that we have in our studio, our studio blog, webshot2, that covers that. Let me see if I can find the link, and webshot2. So, this package for printing HTML, this is a really powerful package for doing all sorts of great things, like basically just taking screenshots. So, here is a screenshot of the CRAN and the R statistical project homepage, from R 4.1 and the base R pipe, so pretty exciting stuff, and just being able to take images of that. So, you can basically pass any HTML into that. It doesn't have to be a web page. It could be locally generated HTML as well.
Can you ask Knitter to read several .R files? Absolutely. So, you could either source or Knitter read chunk from multiple times. So, you can imagine I have 10 different .R files. You could read all those into a parent R Markdown document and execute the code there.
What are the best practices to produce Word documents from R Markdown? So, for Word documents from R Markdown, there's kind of two ways of doing it. You can do it with R Markdown proper, and there's also what's called the Office First, that is a really powerful environment for just working with Office things. You can imagine PowerPoint, Excel, and Word, like the kind of Microsoft Office stack. You can do a lot of those different things with R and with R Markdown. There are certain limitations or certain things you have to work harder to do, but I think that you can still generate useful things from R Markdown into Word to do those.
When do you think someone should use R scripts over R Markdown files? I try and almost always use R Markdown files if I'm doing anything that is useful for that. So, anything where I'm creating an output or I'm trying to capture my train of thought. I know there are times where folks are like, well, I have to send a .R file out to a high performance computing cluster. That's fine. You can use a .R file, and you can still do useful workflows where if I'm in a .R file, I can create like a section label or something. So, with command shift R, I can do cool label, and this will put a separator there where I'm doing labels, or I can do pound pound four dashes to also create a section label. What this does is not only you're writing comments about what you're doing, but if you do want to bring these into R Markdown in the future, now you can use code chunk and read code chunk to pull those in usefully into an R Markdown file. That being said, I find that working R Markdown, especially with the visual editor, so the ability to not only just see the raw plain text or work with the plain text, but also have the rendered output and the ability to interject all sorts of different things that can insert a level one heading. The amazing things you can do with R Studio and R Markdown are worth it, although .R files can do the exact same with R functions.
Does blastula run inside a Docker container on a virtual Linux server? Does it have limitations on the size of the email attachment? So, blastula, like anything else, could run inside a Docker environment. The way that blastula works is either you locally generate an HTML file and send it via SMPP, so I actually render an actual email and then send it via Gmail, for example, or I use RStudio Connect to render it on a server somewhere. RStudio Connect doesn't require Kubernetes or doesn't require Docker. It just runs on a traditional bare metal server, like on-premise or a virtual cloud environment, so you don't need Docker in that workflow. If you wanted to use Docker with blastula, you could, but there's no requirement to do that.
Limitations on the size of the email? I do think that the size of the email is more limited by your server client for sending emails or your web client. I know that, for example, I think Gmail has a size limit on images, so if you try and send a gigabyte of data via email, Gmail's just not going to let you do that. That's not a blastula thing, that's just a Gmail thing. But you can attach basically anything you can create in R, you can attach from email, so PDFs, Excel files, CSVs, RDS files, images, entire reports or .html files, those can all be attached.
Things that are in line in blastula, and I think we actually have a control document, I can show this, we're way over, but we're just going to have fun with that. Let's look at a blastula email. That's not the one I wanted. Penguin emailer. There we go. So when I actually render the email, this is a preview that you can run with the package. This has not been sent, but it shows you what the email would look like as a preview. So this is an embedded ggplot, it's literally inline, so in your actual email that you send to someone, it'll have this text and it will have this image. However, some clients are very aggressive with stripping HTML. So if you tried to, say, do a table with GT, that might not render exactly as you want. Not because GT is doing anything wrong, but just because your email client can't parse HTML at that complexity. So what you can do instead is attach an image directly, and that will typically work in any of the clients. The one addendum there, though, is that attaching tables as images does remove all the metadata of a table and essentially makes it an image, like a graphic. So it might be better to attach a report and just say, like, here are some quick summaries there. But for a lot of email clients, you can still embed tables within them.
All right, I think that's actually all of it. We still have around 400 people here, so thank you for spending some time with me and going a bit over. Have a wonderful weekend, be safe, you know, enjoy our markdown, have a good time, and we will see you next time. Tom logging off, closing down a lot of things, and have a good one.