虽然发送 HTML 邮件sendmailR
并不简单,但可能基于去年与包作者的邮件讨论(再次感谢 Olaf Mersmann 的友好帮助) - 只需覆盖Content-Type
标题即可。例如:
msg <- mime_part('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>HTML demo</title>
<style type="text/css">
</style>
</head>
<body>
<h1>HTML demo</h1>
</body>
</html>')
## Override content type.
msg[["headers"]][["Content-Type"]] <- "text/html"
from <- '<foo@example.com>'
to <- "<bar@example.com>"
subject <- "HTML test"
body <- list(msg)
sendmail(from, to, subject, body, ...)
另一方面,没有真正需要 HTML 来呈现表格或以data.frame
人类可读的格式。例如,可以将 R 对象转换为降价的ascii
包或我的pkg。pander
快速演示:
> library(pander)
> panderOptions('table.split.table', Inf)
> pander(head(iris, 3))
-------------------------------------------------------------------
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
-------------- ------------- -------------- ------------- ---------
5.1 3.5 1.4 0.2 setosa
4.9 3 1.4 0.2 setosa
4.7 3.2 1.3 0.2 setosa
-------------------------------------------------------------------
> pander(head(iris, 3), style = 'grid')
+----------------+---------------+----------------+---------------+-----------+
| Sepal.Length | Sepal.Width | Petal.Length | Petal.Width | Species |
+================+===============+================+===============+===========+
| 5.1 | 3.5 | 1.4 | 0.2 | setosa |
+----------------+---------------+----------------+---------------+-----------+
| 4.9 | 3 | 1.4 | 0.2 | setosa |
+----------------+---------------+----------------+---------------+-----------+
| 4.7 | 3.2 | 1.3 | 0.2 | setosa |
+----------------+---------------+----------------+---------------+-----------+
如果要将其连接到电子邮件正文,请改用pander.return
返回字符向量而不是写入控制台。还有一些其他可用style
的 table ,也有一些有用的,panderOptions
例如设置小数点、日期格式等:http ://rapporter.github.io/pander/