【问题标题】:No line breaks inside code chunks代码块内没有换行符
【发布时间】:2017-04-25 06:32:57
【问题描述】:

我在 Mac 上使用 R v. 3.3.2 和 RStudio v. 1.0.44。我喜欢使用 RMarkdown 和新的 Markdown Notebook 风格。但是,我最近注意到了一种新行为。我的 R 代码块中的换行符不会反映在 HTML 笔记本文件中。例如,我的 .Rmd 文件中的代码块如下所示:

```{r}
# Creating id for each participant
class_survey$id <- rownames(class_survey)

# Reoder the columns in the data frame so that ID comes first
class_survey <- class_survey[c(44, 1:43)]

# Rename the variables
class_survey <- class_survey %>%
  rename(children = Q19_1, gender = Q26, color = Q27)
```

在 nb.html 文档中呈现如下:

# Creating id for each participant
class_survey$id <- rownames(class_survey)
# Reoder the columns in the data frame so that ID comes first
class_survey <- class_survey[c(44, 1:43)]
# Rename the variables using dplyr
# new name = old name
class_survey <- class_survey %>%
  rename(children = Q19_1, gender = Q26, color = Q27)

我回过头来查看我的一些“旧”nb.html 文件,发现以前保留了换行符。有谁知道为什么这种行为会改变,更重要的是,是否有办法将其改回来?

【问题讨论】:

  • 这真的很奇怪。对我来说(MacOS Sierra、R v3.3.1、Rstudio v.1.0.44)呈现为 HTML 会保留换行符....
  • 来自 RStudio 的您好!看起来这是我们笔记本渲染器中的一个错误。我们已经与我们的开发团队取得了联系。
  • @Jonathan 感谢您告诉我们!
  • 密切相关的问题,显然是最新版本的 RStudio 中的一个错误:github.com/rstudio/rstudio/issues/6399

标签: r rstudio knitr r-markdown rnotebook


【解决方案1】:

如果有人遇到这个问题(我在发布半年后仍然存在),您可以编织到 HTML 文档,代码中的换行符会神奇地出现。不确定为什么在 Rstudio 中使用“预览笔记本”功能按钮时所有链接中断都消失了(即使您在新标签页中打开)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-02
    • 1970-01-01
    • 2020-08-26
    • 2021-07-10
    • 2018-08-29
    • 1970-01-01
    • 2019-12-03
    相关资源
    最近更新 更多