首页 > 解决方案 > 在 Windows 上导入 R(用于 xkcd 包)中的 xkcd 字体

问题描述

我不习惯回答自己的问题。但是,我认为该解决方案将来可能会使某人受益(请参阅答案)。无法在包的 github(只读镜像)上发布此问题。

我在 Windows 上的 R 中安装 xkcd 字体时遇到了很多麻烦,尤其是对于最新版本的 R (4.1.1)。操作系统上有这个解决方案,它不适用于 Windows。它需要这个答案和这个答案(两个不相关的问题)才能在 R 中使用字体。

标签: rfonts

解决方案


这是我达到的解决方案。

下载必要的软件包。

install.packages("extrafont","remotes","xkcd")
library(extrafont)
library(remotes)

In system2(ttf2pt1, c(args, shQuote(ttfiles[i]), shQuote(tmpfiles[i])), : running command问题之一是通过降级Rttf2pt1到版本 1.3.8解决的错误消息[...]

remotes::install_version("Rttf2pt1", version = "1.3.8")

下载字体并确保它在工作目录中(应该是)。

download.file("http://simonsoftware.se/other/xkcd.ttf", dest = "xkcd.ttf", mode = "wb")

导入字体的原始描述不起作用(请参阅vignette("xkcd-intro"),必须将路径重定向到工作目录。

font_import(paths = getwd(), pattern = "[X/x]kcd", prompt = FALSE)

加载字体和 xkcd 包现在应该可以工作了。

loadfonts(device = "win")
library(xkcd)

包 xkcd 及其功能不应正常工作。


推荐阅读