0

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).

html output of my .Rmd file

This is the code i use:

---
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)
```

And my session info:

> 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

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

Console tab in Chrome

piptoma
  • 754
  • 1
  • 8
  • 19
  • works fine for me, looks like some link to javascript or css reference is missing in your screenshot. Is javascript unabled or all the css there in the produced file ? – R. Prost Aug 23 '18 at 08:04
  • how do I check for disabled javascript and css? I can open an old .html I compiled 6 months ago (on a different machine) and the old .html looks just fine and works as expected. – piptoma Aug 23 '18 at 08:10
  • Work fine for me too, does the preview with RStudio work ? – Alexandre georges Aug 23 '18 at 08:16
  • You could try to open the file in the old machine. Or you can look at the html code from the file, you should have some javascript and css in there especially for the menu. Maybe use the latest version of R too markdown has probably changed a lot since september 2017 – R. Prost Aug 23 '18 at 08:18
  • Preview in RStudio does not work either. It seems like javascript is missing in the html. How can I fix this? – piptoma Aug 23 '18 at 10:36
  • open it in chrome, F12 to get into developer tools, did you get any error under console tab? By the look of It, I suspect that the CSS styles are not loaded/rendered – TC Zhang Aug 23 '18 at 23:43

1 Answers1

0

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"

After changing the first location to

.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"

the .Rmd renders as expected :).

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))
})()

Created on 2018-09-24 by the reprex package (v0.2.1)

piptoma
  • 754
  • 1
  • 8
  • 19