【问题标题】:trim white space for print command in r markdown在 r markdown 中为打印命令修剪空白
【发布时间】:2018-04-30 22:36:47
【问题描述】:

当我使用命令print(df[[i]]) 打印数据帧的字符变量时,R Markdown 会在行之间显示不需要的空格

我想要的输出将保留换行符,但行之间没有空格,类似于以下内容。我可以在 R 中使用命令 print(df[[i]]) 获得它,但我无法在 R Markdown 中获得它

[1] "No negative points"                                                                                                                                                                                                                              
[2] "The course was too short, not all interesting parts of the method could be covered."                                                                                                                                                             
[3] "the exercises to do at home were done together during course hours, which took too long in comparison to learning new stuff daily.  furthermore, I would have wished for even more theoretical input instead of the long R exercises (see above)"

更新:问题似乎是在中间的乳胶文件中有时降价避免插入//。下面以markdown产生的latex代码为例

{[}1{]} ``good overview over underlying principles of web scraping''\\
{[}2{]} ``none''\\
{[}3{]} ``very well presented''\\
{[}4{]} ``- clear distinction between `big data' and `medium data' -
insight into what R can do in terms of webscraping'' {[}5{]} ``- a good
insight into what is possible with R w.r.t. webscraping'' 

感谢任何帮助

【问题讨论】:

  • 到目前为止你尝试了什么?
  • 我尝试使用 trimws() 和 markdown 选项进行白色剥离,但没有成功

标签: r r-markdown


【解决方案1】:

鉴于此:

```{r}
df <- data.frame(c("No negative points", "The course was too short, not all interesting parts of the method could be covered.", "the exercises to do at home were done together during course hours, which took too long in comparison to learning new stuff daily.  furthermore, I would have wished for even more theoretical imput instead of the long R exercises (see above)"), stringsAsFactors = FALSE)
```

尝试在 Markdown 中为 R 块使用 results 参数:

```{r, results = "asis"}
print(df[[1]])
```

对于像这样的输出:

【讨论】:

  • 这项工作,但有时无法在新行上打印。 Example
  • @AlbertoStefanelli - 这很奇怪 - 我无法复制该错误。你能展示产生该输出的代码(包括 r 块参数)吗?
  • 主帖更新
猜你喜欢
  • 1970-01-01
  • 2023-03-23
  • 1970-01-01
  • 1970-01-01
  • 2013-10-27
  • 1970-01-01
  • 2018-08-26
  • 2017-03-16
  • 1970-01-01
相关资源
最近更新 更多