小编Yih*_*Xie的帖子

如何使用没有原始降价输出的knitr块向绘图添加元素?

出于纪录目的,我想要一些html输出中的绘图代码,而不是绘图.之后,我必须调用绘图代码,并在绘图中添加一些内容,但只能看到附加代码.我试过这个:

```{r non.finished.plotting, eval=FALSE}
    plot(1,type="n")
```
Some explanatory text here in the output:
"This produces an empty plot, and we could now add some points to it manually."

```{r add.layer, fig.width=5, fig.height=5}
<<non.finished.plotting, echo=FALSE>>
points(x=rnorm(100,1,0.1), y=rnorm(100,0.8,0.1) )

```
Run Code Online (Sandbox Code Playgroud)

我在Yihui的发现了echo符号,但是当我编织它时,我在输出中收到一条错误信息.

## Error: plot.new has not been called yet
Run Code Online (Sandbox Code Playgroud)

我也尝试摆弄大块选项,但我找不到能满足我想要的组合.(对不起,这是非常基本的,但我没有找到类似这个例子的东西.)

markdown plot r knitr

8
推荐指数
1
解决办法
2569
查看次数

使用knitr从R中编写html

也许我错过了显而易见的事情,但我一直在努力寻找以下示例:我想使用该knitr软件包将我在R中的分析报告写入html文件.我已经找到了这个stitch()函数,但是如果能够更好地控制哪些结果和图表被写入html并且哪些不是.原则上我希望能够编写以下代码:

# some dummy code
library(ggplot)
data <- read.table('/Users/mydata', header=TRUE)
model <- lm(Y~X*Y, data)

# write this result to html:
summary(model)
Run Code Online (Sandbox Code Playgroud)

reporting r knitr

7
推荐指数
2
解决办法
3703
查看次数

如何在解析()后保留多字节字符

当我在Windows下解析具有非本机字符的R代码时,这些字符似乎变成了它们的Unicode表示形式,例如

Encoding('?')
# [1] "UTF-8"
parse(text="'?'")
# expression('<U+011F>')
parse(text="'?'", encoding='UTF-8')
# expression('<U+011F>')
deparse(parse(text="'?'")[1])
# [1] "expression(\"<U+011F>\")"
eval(parse(text="'?'"))
# [1] "<U+011F>"
Run Code Online (Sandbox Code Playgroud)

由于我的语言环境是简体中文,我可以解析具有中文字符的代码,例如

parse(text="'??'")
# expression('??')
Run Code Online (Sandbox Code Playgroud)

我的问题是,如何?在这个例子中保留字母之类的字符?或者至少我怎样才能deparse()在表达之后"重建"原始人物?

我的会话信息:

> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: i386-w64-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=Chinese (Simplified)_People's Republic of China.936 
[2] LC_CTYPE=Chinese (Simplified)_People's Republic of China.936   
[3] LC_MONETARY=Chinese (Simplified)_People's Republic of China.936
[4] LC_NUMERIC=C                                                   
[5] LC_TIME=Chinese (Simplified)_People's Republic of China.936    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     
Run Code Online (Sandbox Code Playgroud)

windows encoding parsing r

7
推荐指数
1
解决办法
544
查看次数

是否有knitr选项强制包含R文件中的UTF-8编码?

我正在使用Windows 7,R2.15.3和RStudio 0.97.320与knitr knitr_1.1.6(在Yihui于3月12日修复'编码:编织和子文件'问题后下载)

> sessionInfo()
R version 2.15.3 (2013-03-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=Spanish_Argentina.1252  LC_CTYPE=Spanish_Argentina.1252    LC_MONETARY=Spanish_Argentina.1252
[4] LC_NUMERIC=C                       LC_TIME=Spanish_Argentina.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] lattice_0.20-13    pixmap_0.4-11      RColorBrewer_1.0-5 ade4_1.5-1         pander_0.3.1      
[6] xtable_1.7-1      

loaded via a namespace (and not attached):
[1] digest_0.6.3   evaluate_0.4.3 formatR_0.7    grid_2.15.3    knitr_1.1.6    stringr_0.6.2  tools_2.15.3 
Run Code Online (Sandbox Code Playgroud)

我把R代码放在像这样的文件中:

## @knitr RunMyCode 
print('Called from .R file: á é í ó ú ñ')  

# Workaround
my.text <- 'á é í ó …
Run Code Online (Sandbox Code Playgroud)

r utf-8 character-encoding knitr

7
推荐指数
1
解决办法
3286
查看次数

knitr中的非英语特殊字符

我正在使用knitr 1.1.在R 3.0.0和WinEdt(RWinEdt 2.0)中.我遇到了knitr识别瑞典字符(ä,ö,å)的问题.这不是R的问题; 这些字符甚至可以在文件名,目录名,对象等中识别.在Sweave中,它也不是问题.

我已经\usepackage[utf8]{inputenc}在我的文档中,但knitr似乎无法处理特殊字符.运行knitr后,我收到以下消息:

Warning in remind_sweave(if (in.file) input) :
It seems you are using the Sweave-specific syntax; you may need Sweave2knitr("deskriptiv 130409.Rnw") to convert it to knitr

processing file: deskriptiv 130409.Rnw

(*) NOTE: I saw chunk options "label=läser_in_data"
please go to http://yihui.name/knitr/options (it is likely that you forgot to 
quote "character" options)

Error in parse(text = str_c("alist(", quote_label(params), ")"), srcfile = NULL) : 
1:15: unexpected input
1: alist(label=lä
                 ^
Calls: knit ... parse_params -> withCallingHandlers …
Run Code Online (Sandbox Code Playgroud)

r utf-8 character-encoding special-characters knitr

7
推荐指数
1
解决办法
4465
查看次数

如何在knitr中禁用整个代码块?

有没有办法完全禁用knitr中的代码块,以便既不评估也不输出?

r knitr

7
推荐指数
1
解决办法
5041
查看次数

rmarkdown生成的pdf文档中表格的标题

如何在rmarkdown生成的pdf_document中获取我的表浮动的标题?

运用

output:
  pdf_document:
    fig_caption: true
Run Code Online (Sandbox Code Playgroud)

```{r, fig.cap='a caption'} 
myplot 
```
Run Code Online (Sandbox Code Playgroud)

使用myplot和指定的标题生成浮动数字.

如何使用xtable生成的表实现相同的功能?

```{r, results='asis', fig.cap='table caption'}
    print(xtable(table), comment = FALSE)
```
Run Code Online (Sandbox Code Playgroud)

我曾尝试在print.xtable中使用floating.environment ='figure',但无济于事.

r xtable knitr r-markdown

7
推荐指数
2
解决办法
4382
查看次数

块的时间?

有没有办法报告计算每个块需要多少时间?我正在从一些大型脚本创建一个文档,很高兴知道时间在哪里.我确实使用了缓存功能,所以当缓存对象时,使用文档的速度并不太慢,但我想隔离缓慢的块,看看除非绝对需要,否则我可以阻止它们被重新计算.

一种想法是例如将每个块包装在system.time()中并报告每个块输出下面的system.time,或者在边缘...

再次感谢Yihui这样优秀的软件.

r knitr

7
推荐指数
1
解决办法
672
查看次数

如何在选项卡/选项卡集 [rmarkdown / bootstrap] 上添加下拉菜单

Bootswatch 的文档建议我可以使用选项卡集中选项卡的下拉菜单:

在此处输入图片说明

如何使用 Rmarkdown 实现这一目标?我试过了:

# SECTION 1 {.tabset .tabset-fade}

## Section 1.1 

## Section 1.2 {????something here?????}
 ### Section 1.2.1  <<<<<<<<< want this to appear under the dropdown menu
Run Code Online (Sandbox Code Playgroud)

html r twitter-bootstrap r-markdown blogdown

7
推荐指数
2
解决办法
9609
查看次数

我如何仅在R markdown的引文中提供年份?

我的rmarkdown脚本如下所示:

---
title: "Untitled"
author: "me"
date: '`r format(Sys.time(), "%d %B, %Y")`'
output:
  pdf_document: default
  bibliography: bibliography.bib
---

In his book Helsel explains how to approach censored environmental data [@helsel_statistics_2012].
Run Code Online (Sandbox Code Playgroud)

我的.bib文件如下:

@book{helsel_statistics_2012,
    address = {Hoboken, N.J},
    edition = {2nd ed},
    series = {Wiley series in statistics in practice},
    title = {Statistics for censored environmental data using {Minitab} and {R}},
    isbn = {978-0-470-47988-9},
    publisher = {Wiley},
    author = {Helsel, Dennis R.},
    year = {2012},
    note = {00003 OCLC: ocn748290711},
    keywords = …
Run Code Online (Sandbox Code Playgroud)

r bibliography pandoc knitr r-markdown

7
推荐指数
1
解决办法
783
查看次数