rmarkdown文件(.Rmd)的html在浏览器中未正确显示 [英] html of rmarkdown file (.Rmd) is not displayed correctly in browser

查看:1164
本文介绍了rmarkdown文件(.Rmd)的html在浏览器中未正确显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When I knit my .Rmd to html, it does not get displayed properly, i. e. it seems like something is wrong with the format (see screenshot below): The two hyperlinks do not work, the font is not sans-serif, there is no table of contents, etc. I used the same code on a different machine 6 months ago and it rendered as expected. However, today it does not. Does anybody have an idea why the html looks ugly? It seems not to depend on the browser I open the html with (tested it in IE and Chrome).

这是我使用的代码:

---
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,然后在控制台下显示


update: Opened the html in Chrome, pressed F12, and under console it says

推荐答案

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

A friend of mine got the solution for this problem: The .libPaths() in our company was defined as

.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呈现预期的效果:).

the .Rmd renders as expected :).

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

We placed the following function in our .Rprofile. It creates the directory step-by-step and adds it to .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软件包(v0.2.1)于2018-09-24创建

这篇关于rmarkdown文件(.Rmd)的html在浏览器中未正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆