German Umlaut characters in R markdown

烂漫一生 提交于 2019-12-04 00:06:05

问题


How can I display non-English characters in R-markdown? In an otherwise English document, I would like to render a single 'u' with two dots (an 'umlaut') on top of it. It is the correct spelling for 'u' in the name 'Muller.'


回答1:


You can use standard HTML code for this. For example, the German letter ä can be displayed by placing the corresponding vowel after an ampersand sign, followed by uml;, i.e., ä.

Here's an example of a .Rmd file:

---
title: "Umlauts with Rmarkdown"
output: html_document
---

## This is a sentence with many umlaut characters:

Herr Müller sagt: "Über den Wolken können Sonnenuntergänge 
besonders schön sein."




回答2:


We can do one better than in @RHertel answer. While the explicit use of HTML markup works, it may restrict us to HTML output -- which is uncool.

Checking with the RStudio documentation you see that UTF-8 is already the default (though I did an extra 'File -> Save with Encoding' which just showed that it already was at UTF-8). Hence it is just a matter of entering proper unicode characters. Below is a little variation on the standard file RStudio creates:

---
title: "Encoding Demo"
author: "Dirk Eddelbüttel"
date: "2/27/2016"
output: html_document
---

## R Markdown

Herr Müller sagt: "Über den Wolken können Sonnenuntergänge besonders schön sein."

which results in the following HTML:



来源:https://stackoverflow.com/questions/35671530/german-umlaut-characters-in-r-markdown

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!