{emayili} Right-to-Left

[This article was first published on R - datawookie, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Yoav Raskin suggested that it would be useful to support right-to-left (RTL) text in {emayili}, so that languages like Hebrew, Arabic and Aramaic would render properly. I’ll be honest, this was not something that I had previously considered. But agreed, it would be a cool feature.


[1] '0.5.5'


The first step to make this happen was writing a short CSS file, rtl.css.

.rtl {
  direction: rtl;
  color: green;

body {
  margin: 20px 0px;

figure {
  margin-bottom: 20px;

.rtl figcaption {
  direction: inherit;

This makes use of the CSS direction property (which by default is ltr), setting it to rtl. I’m also colouring the RTL text in green, just to make things super clear.

I put together a simple .Rmd file to test, rtl.Rmd, rendered it into a message and then dispatched.

envelope() %>%
  subject("Right-to-Left Text") %>%
  render("rtl.Rmd", css_files = "rtl.css")

The extra CSS is included via the css_files parameter.

🚨 If you want this to work nicely on Gmail then you’ll also need to set include_css = c("rmd", "highlight") because Gmail doesn’t currently appreciate Bootstrap CSS.

In the interests of brevity the contents of rtl.Rmd have been appended to the end of the post.

And this is what the delivered email looks like:

Having a rtl class allowed me to mix both left-to-right and right-to-left content in the same message. In reality this is a rather unlikely requirement. To use RTL for the entire message just adapt the CSS as follows:

body {
  direction: rtl;

If there are other tweaks that I can make on {emayili} to ensure that it supports your requirements, please raise an issue on the repository.

The {emayili} package is developed & supported by Fathom Data.

Here are the contents of rtl.Rmd:

output: html_document

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer non magna
magna. Etiam eu sapien nulla. Cras ac lectus non urna scelerisque porttitor ac
non tortor.

<div class="rtl">
צחוק המעבורת, מהדובים של הכרית החופשית. מי רוצה לפספס, עצוב בחצר האחורית, כד
רך. עכשיו הכאב של הכאב הוא לא הכאב של הטרדה, הצורך של אגמי החלבון של התפוז.
אלמנט כלשהו, ​​וגם לא יסוד כימי של נדל"ן, מראית עין של מגוון כלי רכב לנחות, רגע
לפני הספד החיים. אניאס הוא מחבר רכיב המחיר. אין פחד אלא אם להיות כנים. אני חי
במייסר העצוב של הכדורגל שלי, בסמך הזן כמובן. אבל המענה והקשתות, או קצות האורקים.
אל האגם או לפניו. הזמן של העמק לוקח. אפילו הפחד מהפחד, הקשתות או המעבורת, אתת

```{r pressure, out.width="50%", fig.cap="כיתוב דמות", fig.class="rtl"}
par(mar = c(5, 4, 1, 1))
plot(pressure, xlab = "טֶמפֶּרָטוּרָה", ylab = "לַחַץ", mar = c(5, 4, 0, 2))

<div class="rtl">
המחלה נושאת את הסבירות לסוף השבוע, והפחד מהכדורגל קשה. אבל האריה והאריה והילדים
נמצאים במיטה. זה ברוטב צריך להגיד. אבל מבחינתו, צרות החיים מותירות הרבה חיים,
הקריקטורה זקוקה לארוסים. עכשיו אני שונא את הגורמים, לא את הכאב ולא את הסביבה,
הכניסה קלה. עכשיו הכניסה לחיי.

Cras fringilla nunc in tellus sagittis accumsan. Mauris nisi tellus, congue sit
amet turpis nec, accumsan lacinia neque. Nulla facilisi.

To leave a comment for the author, please follow the link and comment on their blog: R - datawookie.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)