- 3 Minutes Wednesdays
- Posts
- 3MW (Meet {glue} on steroids đ„)
3MW (Meet {glue} on steroids đ„)
Guten Tag!
Many greetings from Ulm, Germany. Last week, I mentioned that {epoxy}
is Garrick Aden-Buie's cool R package that makes formatting texts much easier.
Let's have a look how that works. But first, let me throw in my regular announcements.
YT promo
Huge color legends waste toooo much space. Thatâs why itâs better put that color into your title instead. This strategy also works with different symbols. In this video, I show you how to get colors AND symbols into your ggplot titles.
Course progress
My dataviz course is making progress. This week I added a clarified the scope of the course. Itâs not all principles without practice.
I give you the high-level principles and how they work in ggplot in part 1. In part 2, I show you how the principles can be applied to specific chart types.
Basically, you can watch the first part to get the principles. And then you can jump to any video in part 2. If youâre interested in this course or want to get the chance to beta-test it, donât forget to sign up to the course mailing list.
Now letâs dive into the newsletter. As always, you can find the full code on GitHub.
Comparison with {glue}
In {epoxy}
, you can use a glue()
-like syntax but {epoxy}
comes with much more formatting features compared to glue()
. Hereâs an example of that:
Combine multiple formatting instructions
You can also throw together multiple formatting instructions to make your texts pretty.
But watch out here. The formatting order can be important.
Render text instead of Markdown
As you can see, the output of the previous code is Markdown. If you want to render that into your document, you can use, say, epoxy_html()
to do just that. Just watch out, that you will have to use double brackets in this case.
Hereâs the output of that:
Have a look. Something is wrong here. Why is the text not bold in the output? Well, if you look at the html source code, you will see that the output is an inline span
-tag with class bold
.
To avoid that we have to actually use @
instead of .
So why was the dollar sign rendered properly? It seems that in HTML output, {epoxy}
just converts the first instruction to a CSS class. Hence, if we want to assign multiple classes we have to piece them together without empty spaces.
Then, you will see that the text is not formatted at all but the span-tag has all the classes
Now without delving too much into HTML & CSS, let me just mention that this is an amazing tool to apply website-wide styling. Just add CSS classes to your outputs and style all of them with a single CSS-file.
Write whole chunks
The cool thing that makes {epoxy}
so great for reports is that you can use whole chunks of text and include specific data-driven values inside of that.
Let's define some new numbers that we can use in that text.
And then, we add an {epoxy}
chunk.
Note that although I use this in a Quarto file to generate an HTML-file, I could use single-brackets. If I want to enforce the behavior of epoxy_html()
(that can also add CSS classes), I will have to use an {epoxy_html}
chunk. In any case, the rendered text looks like this:
Avoid code repetition
If we wanted to avoid typing out .bold
in our previous chunk, we could set the âtransformerâ of that chunk to make all inputs bold.
This works by using epoxy_transform()
to chain the "bold transformerâ with the âinline transformerâ that we have been using by default anyway.
This transformer thing is a bit of a hard concept to wrap your head around. So donât fuss about it if you donât get it immediately. It took me a bit to figure it out too.
Itâs not all about the numbers
Interestingly, {epoxy}
doesnât do only numbers. You can also transform texts.
Here, I formatted the text by making everything into lower case and then applying title case. Pretty easy to do that by combining the formatting keywords.
Work with more than single outputs
What I find even more fascinating is that {epoxy}
can actually handle more than a single input. Hereâs a simple example from the docs:
Right now, this gives you four lines of output. But you can actually determine how to collapse these into a single line.
This works with keywords like .and
, .or
as well as .comma
. Judging from the next output, I think you can guess what each of those keywords does.
Well, that worked wonderfully. But it doesn't make that much sense here, does it? Oh well, I think in a demo like this, that's okay. đ
Hope youâve enjoyed this weekâs newsletter. If you want to reach out to me, just reply to this mail or find me on Twitter, uhhh I mean X. More recently, you can also find me on LinkedIn (which I will be using more and more).
See you next week,
Albert đ
If you like my content, you may also enjoy these:
Reply