rmarkdown文件(.Rmd)的html在浏览器中无法正确显示

时间:2018-08-23 07:56:38

标签: html r r-markdown knitr

当我将.Rmd编织为html时,它无法正确显示。 e。格式似乎有问题(请参见下面的屏幕截图):这两个超链接不起作用,字体不是sans-serif,没有目录等。我在6个月的不同机器上使用了相同的代码之前,它按预期呈现。但是,今天没有。有谁知道为什么html看起来丑陋?似乎不依赖于我打开html的浏览器(在IE和Chrome中测试过)。

html output of my .Rmd file

这是我使用的代码:

---
title: "my title"
author: "subtitle"
date: "my name, `r format(Sys.time(), '%d. %B, %Y')`"
output:
  html_document:
    code_folding: hide
    highlight: haddock
    number_sections: yes
    toc: yes
    toc_float: yes
---

# section
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod 
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At 
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd 
gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum 
dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor 
invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero 
eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no 
sea takimata sanctus est Lorem ipsum dolor sit amet.

```{r, warning = FALSE}
head(mtcars)
```

我的会话信息:

> sessionInfo()
R version 3.4.2 (2017-09-28)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=German_Switzerland.1252  LC_CTYPE=German_Switzerland.1252    
LC_MONETARY=German_Switzerland.1252
[4] LC_NUMERIC=C                        LC_TIME=German_Switzerland.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] compiler_3.4.2  backports_1.1.1 magrittr_1.5    rprojroot_1.2   
htmltools_0.3.6 tools_3.4.2     yaml_2.1.15    
 [8] Rcpp_0.12.14    stringi_1.1.6   rmarkdown_1.8   knitr_1.17      
stringr_1.2.0   digest_0.6.12   evaluate_0.10.1

更新:在Chrome中打开html,按F12,然后在控制台下显示

Console tab in Chrome

1 个答案:

答案 0 :(得分:0)

我的一个朋友找到了解决此问题的方法:我们公司中的.libPaths()被定义为

.libPaths()
#> [1] "\\\\userhome/my_user_name/R/win-library/3.4"   # note the four \\\\
#> [2] "C:/Program Files/R/3.4.2/library"

将第一个位置更改为

.libPaths()
#> [1] "C:/Users/my_user_name/R/win-library/3.4.2"     # path starts with C:/
#> [2] "C:/Program Files/R/3.4.2/library"

.Rmd呈现预期的效果:)。

我们在.Rprofile中放置了以下函数。它会逐步创建目录并将其添加到.libPaths()

# install packages locally within user profile
(function() {
  components <- list('C:/', 'users', Sys.info()['login'], 'R',
                     'win-library', paste0(R.Version()$major,
                                           '.',
                                           R.Version()$minor))

  # loop over components and create dir step-by-step
  # (recursive = TRUE leads to errors)
  for (k in 4:length(components)) {
    p <- do.call(file.path, components[1:k])
    dir.create(p, showWarnings = FALSE, recursive = FALSE)
  }

  path <- do.call(file.path, components)
  .libPaths(c(path, .Library))
})()

reprex package(v0.2.1)于2018-09-24创建