使用 R Markdown 输出 pdf。kable() 效果很好,但是当我添加longtable=T标题时,不再扩展表格的整个宽度。我似乎找不到一个可以控制此处标题详细信息的参数。我可以将标题移动到每个代码块的输出,但如果可能的话,我宁愿使用 kable 中的内置功能。
谢谢!
---
title: "test"
author: ""
date: "September 6, 2017"
output:
pdf_document:
latex_engine: xelatex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(kableExtra)
library(knitr)
library(dplyr)
```
```{r table1}
test <- data.frame(col1=rep("MyLongWordsareLong",5),
col2=rep("MyLongWordsareLong",5),
col3=rep("MyLongWordsareLong",5),
col4=rep("MyLongWordsareLong",5),
col5=rep("MyLongWordsareLong",5),
col6=rep("MyLongWordsareLong",5))
kable(test,format='latex',booktabs=TRUE,
caption="This is my example caption. See how, when I don't use
longtable, it extends the full width of the table, but when I use the
longtable option, it compresses down to only a portion …Run Code Online (Sandbox Code Playgroud) 由于我正在尝试实现其他一些javascript,我希望能够在编译的RMarkdown文件中轻松区分和定位图像.使用这种代码块以标准方式生成的图像
```{r}
plot1 <- ggplot(data = mtcars, aes(x = wt, y = mpg, group = am, color = am)) +
geom_point(size = 3)
plot1
```
Run Code Online (Sandbox Code Playgroud)
结果像HTML一样
<img src = "data:image/png..." width = 1000/>
Run Code Online (Sandbox Code Playgroud)
我希望能够自动为每个图像添加唯一标识符,以便每个这样的调用都会产生类似的结果
<img src = "data:image/png..." id = "plot1" width = 1000/>
Run Code Online (Sandbox Code Playgroud)
我可以用JS写这个,但我想知道是否有办法用一些RMarkdown选项来做到这一点.
xaringan 的键盘快捷键会干扰 DT::datatable() 搜索功能。它甚至可以在xaringan 的示例演示中看到(例如,尝试搜索“m”)。
我怎样才能阻止这种情况发生?实际上不可能在 DT::datatable() 中搜索任何内容。提前致谢!
我想将 RMarkdown 中的 Python 代码块导出到外部文件。knitr::purl()实现了这一点,但我只能让它在 R 代码块上工作。它不适用于除 R 之外的任何其他语言吗?
例如,从下面将 python 代码导出到 my_script.py 文件中。
---
title: "Untitled"
output: html_document
---
## Header
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip
```{python}
x = 10
y = 20
z = x + y
print(z)
```
Run Code Online (Sandbox Code Playgroud) 例如,是否可以导入 Latex 宏文件
\newcommand{\Xcal}{\mathcal{X}
Run Code Online (Sandbox Code Playgroud)
这样我就可以在$...$as之间使用它$\Xcal$?
我正在尝试使用Markdown来编写一个涉及一些R编码的课程的作业问题.因为这些是作业集,我故意编写抛出错误的代码; 是否可以使用Markdown在代码样式中显示R代码而不进行评估(或以某种方式捕获错误)?
我想有一个.Rmd文件的模板,我用它来制作html5幻灯片.通常,模板的开头部分是:
% Title
% Name
% Date
Run Code Online (Sandbox Code Playgroud)
我想自动填写日期,以便模板随时可用.(运行Pandoc才可以看到这里)
这工作但是hacky现在日期和名称显示在主html文件中(在html5处理之前)因为我必须删除%之前这些元素:
% Title
Name
`r as.character(format(Sys.Date(), format="%B %d, %Y"))`
```{r setup, include=FALSE}
# set global chunk options
opts_chunk$set(cache=TRUE)
library(knitr)
```
Run Code Online (Sandbox Code Playgroud)
也许有一个非R,更多的HTML,修复.
我正在使用R中knitr包中的stitch函数为我的学生创建R代码的html文件.
我有几百个R脚本,并且自动创建html页面的过程.
但是,如果我的R脚本包含注释行,例如
## ------示例------
然后是针脚功能thinks这是代码块的标签,并经常删除我脚本的其他部分.
有没有办法在函数turn off 中分块stitch()来传递所有代码as is?我已经查看了内部代码,stitch()并且read_chunk()似乎无法看到它## ----- Example -----是如何知道何时 是块标签.
这是最小的工作示例:R 3.0.1; knitr 1.4.1
# Test out problem with stitch in knitr
my.code <- "# This a sample of R code
x <- 1:10
print(x)
plot(x,x)
## ---------------- Example -----
# Notice that only this part of the code appears in the html file.
x <- 10:30
print(x)
plot(x,x)
NULL
"
writeLines(my.code, con='R.code') …Run Code Online (Sandbox Code Playgroud) 这是一个 rmarkdown 片段:
#Is this even achievable?
```{r echo = FALSE, comment = ""}
install.package(mvbutils)
library(mvbutils)
make.usage.section("paste", env=asNamespace('base'))
```
Run Code Online (Sandbox Code Playgroud)
正如预期的那样(当在 RStudio 中编织到 时pdf)打印出一些类似的东西
paste(..., sep = " ", collapse = NULL)
Run Code Online (Sandbox Code Playgroud)
请注意##,默认情况下没有前导, 附加到函数输出,但在此示例中使用comment标志关闭。是否可以进一步调整该输出的表示,使其等同于(代码突出显示和所有)的输出:
```{r eval = FALSE}
paste(..., sep = " ", collapse = NULL)
```
Run Code Online (Sandbox Code Playgroud)
我正在写一个方法,这会让生活变得非常简单。
使用时
render_book("index.Rmd", "bookdown::pdf_book")
Run Code Online (Sandbox Code Playgroud)
它看起来像一条线,设置边距插入到tex文件中
\usepackage[margin=1in]{geometry}
Run Code Online (Sandbox Code Playgroud)
该bookdown-demo摄制可以用来重现此。
在中index.Rmd,我正在使用
---
date: "`r Sys.Date()`"
knit: "bookdown::render_book"
documentclass: krantz
classoption: numberinsequence,krantz1
bibliography: [book.bib]
biblio-style: apalike
link-citations: yes
colorlinks: yes
---
Run Code Online (Sandbox Code Playgroud)
这正在破坏该样式文件设置的边距。我知道可以修改几何图形选项,但是可以避免生成这条线吗?
谢谢
> sessionInfo()
R version 3.3.3 (2017-03-06)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS Sierra 10.12.4
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] bookdown_0.4
loaded via a namespace (and not attached):
[1] backports_1.0.5 magrittr_1.5 rprojroot_1.2 htmltools_0.3.6
[5] …Run Code Online (Sandbox Code Playgroud) r ×10
knitr ×7
r-markdown ×6
pandoc ×2
xaringan ×2
bookdown ×1
datatables ×1
html ×1
kableextra ×1
longtable ×1
markdown ×1
mathjax ×1
python ×1
remarkjs ×1
rstudio ×1