2
我有一個輸出呈現正確的HTML代碼的功能,但與'results減價文件R代碼塊包圍它=「現狀」`失敗。我將問題追溯回HTML代碼中的空格。我喜歡這些空格,因爲它們使讀取原始HTML文件更容易。如果您想請考慮安裝我的[R包「rockchalk」,你可以運行這一點,看到的一樣。[R降價ASIS突破有效的HTML代碼
我顯示該問題是由空格HTML在以下MRE(其降價對待爲標記爲代碼)而引起的。我可以得到沒有任何額外樣式表魔法的輸出:http://pj.freefaculty.org/scraps/mre.html
向下滾動,您會看到表格已損壞,但在篩選出多餘的空格後,表格會按預期顯示。
在您看來,這僅僅是我的用戶錯誤依賴於HTML代碼中的空格,還是它在R markdown中的「asis」中的錯誤。
---
title: "Guide Documents"
author:
- name: Paul Johnson
affiliation: Center for Research Methods and Data Analysis, University of Kansas
abstract:
Author, please REMEMBER TO INCLUDE AN ABSTRACT BEFORE FINALIZING THIS DOCUMENT!
date: "`r format(Sys.time(), '%Y %B %d')`"
output:
html_document:
highlight: haddock
---
```{r setup, include = FALSE}
##This Invisible Chunk is required in all CRMDA documents
outdir <- paste0("tmpout")
if (!file.exists(outdir)) dir.create(outdir, recursive = TRUE)
knitr::opts_chunk$set(echo = TRUE, comment = NA, fig.path = paste0(outdir, "/p-"))
options(width = 70)
```
```{r myregs}
library(rockchalk)
set.seed(2134234)
dat <- data.frame(x1 = rnorm(100), x2 = rnorm(100))
dat$y1 <- 30 + 5 * rnorm(100) + 3 * dat$x1 + 4 * dat$x2
dat$y2 <- rnorm(100) + 5 * dat$x2
m1 <- lm(y1 ~ x1, data = dat)
m2 <- lm(y1 ~ x2, data = dat)
m3 <- lm(y1 ~ x1 + x2, data = dat)
gm1 <- glm(y1 ~ x1, family = Gamma, data = dat)
or1 <- outreg(list("Amod" = m1, "Bmod" = m2, "Gmod" = m3),
title = "My Three Linear Regressions", float = FALSE, type = "html")
```
```{r browseme}
or1 <- outreg(list("Amod" = m1, "Bmod" = m2, "Gmod" = m3),
title = "My Three Linear Regressions", float = FALSE, type = "html")
```
```{r flawed, results = "asis"}
cat(or1)
```
```{r cleaned, results = "asis"}
or1 <- gsub(" "," ", or1)
or1 <- gsub("^\\ *", "", or1)
or1 <- paste(or1, collapse = "")
or1 <- gsub("\\ \\ \\ \\ \\ \\ ", " ", or1)
or1 <- gsub("\\ \\ \\ ", " ", or1)
cat(or1)
```
```{r sessionInfo, echo = FALSE}
sessionInfo()
```
Available under
[Created Commons license 3.0 <img src="http://crmda.dept.ku.edu/images/cc-3.0.png" alt="CC BY"
style="width: 75px;height: 20px;"/>](http://creativecommons.org/licenses/by/3.0/)
衷心感謝您的關注。我明白。我將刪除空格,因爲我不想添加新的依賴項。 – pauljohn32
@ pauljohn32你能否指定哪些領先空間造成這種情況。我遇到了類似的問題。 – Michael