我已经在Linux mint和Windows 7上安装了Sweave和knitr软件包,它在Windows上运行良好,但在Linux中使用rstudio时却失败了.安装pkgs后,我写了一个简单的dw.Rnw如下:
\documentclass{article}
\begin{document}
The regression model is as follows
<<echo=TRUE>>=
pop=read.table("pop.txt",header=TRUE)
attach(pop)
lm.sol=lm(y~year)
summary(lm.sol)
@
\end{document}
Run Code Online (Sandbox Code Playgroud)
当我按下rstudio中的" 编译PDF " 按钮时,它会返回以下错误消息:
During startup - Warning messages:
1: Setting LC_CTYPE failed, using "C"
2: Setting LC_COLLATE failed, using "C"
3: Setting LC_TIME failed, using "C"
4: Setting LC_MESSAGES failed, using "C"
5: Setting LC_PAPER failed, using "C"
6: Setting LC_PAPER failed, using "C"
7: Setting LC_MEASUREMENT failed, using "C"
> grDevices::pdf.options(useDingbats = …Run Code Online (Sandbox Code Playgroud) 在R中,capture.output()可以stdout将表达式中的输出捕获为字符向量,例如
> x = capture.output(print(1:10))
> x
[1] " [1] 1 2 3 4 5 6 7 8 9 10"
Run Code Online (Sandbox Code Playgroud)
朱莉娅有同等的功能吗?
我不仅希望我的数字出现在我的knitr生成的报告中,而且我还希望将它们输出到单独的文件中.为此,我提供了如下代码:
```{r}
#Plot figure in report
plot(x,y)
#Plot figure in file
pdf(file="MyFig.pdf")
plot(x,y)
dev.off()
```
Run Code Online (Sandbox Code Playgroud)
这很好用,但我希望有一个更优雅的解决方案,已经内置到knitr.是否有一个块选项或类似的东西可以实现相同的结果?
我希望在行中使用R代码作为ar markdown文件中标题的一部分.但是,当我编织文件时,标题上使用的字体是不同的.如何确保字体相同.一个简单的例子如下.
`r 1+1` Header
-------------------------
Run Code Online (Sandbox Code Playgroud) 出于纪录目的,我想要一些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)
我也尝试摆弄大块选项,但我找不到能满足我想要的组合.(对不起,这是非常基本的,但我没有找到类似这个例子的东西.)
我想创建一个tex表使用xtable().这是我在Win 7上使用相同R版本时的最小例子.
\documentclass[a4paper,12pt,twoside]{article}
\begin{document}
<<load-packages,include=TRUE,echo=TRUE>>=
library(xtable)
@
<<testing-xtable,echo=TRUE,cache=FALSE,include=TRUE>>=
tab <- matrix(1:50,nrow=10)
rownames(tab) <- letters[1:10]
print(
xtable(
x=tab,
caption="A table",
label="tab",
align=rep("c",times=6),
digits=3,
display=rep("f",times=6)
),
sanitize.colnames.function=identity,
include.rownames=FALSE,
table.placement="h"
)
@
\end{document}
Run Code Online (Sandbox Code Playgroud)
我得到xlatex()了pdf文档中的逐字代码输出,而不是一个好的表.
这是knitr的输出:
> grDevices::pdf.options(useDingbats = FALSE); require(knitr); opts_knit$set(concordance = TRUE); knit('xtable.Rnw', encoding='UTF-8')
Loading required package: knitr
processing file: xtable.Rnw
|............. | 20%
ordinary text without R code
|.......................... | 40%
label: load-packages (with options)
List of 2
$ include: logi TRUE
$ echo : logi TRUE …Run Code Online (Sandbox Code Playgroud) 我们可以使用set.seed()在R中设置随机种子,这具有全局效应.这是一个简单的例子来说明我的目标:
set.seed(0)
runif(1)
# [1] 0.8966972
set.seed(0)
f <- function() {
# I do not want this random number to be affected by the global seed
runif(1)
}
f()
# [1] 0.8966972
Run Code Online (Sandbox Code Playgroud)
基本上我希望能够避免全局随机种子(即.Random.seed)在本地环境(例如R函数)中的影响,这样我就可以实现用户无法控制的某种随机性.例如,即使用户有set.seed(),他每次调用此函数时仍会得到不同的输出.
现在有两个实现.第一个依赖于set.seed(NULL)让R每次想要得到一些随机数时重新初始化随机种子:
createUniqueId <- function(bytes) {
withPrivateSeed(
paste(as.hexmode(sample(256, bytes, replace = TRUE) - 1), collapse = "")
)
}
withPrivateSeed <- function(expr, seed = NULL) {
oldSeed <- if (exists('.Random.seed', envir = .GlobalEnv, inherits = FALSE)) {
get('.Random.seed', envir = …Run Code Online (Sandbox Code Playgroud) 我有一个长的矢量字符串(DNA序列),最多可以添加到我的knitr报告输出中的几千个连续字符.RStudio在控制台中完美地处理文本包装,但是当我生成knitr html输出时,我只能看到一行文本,它只是在页面上运行.
RStudio输出

编织输出

任何调整knitr输出以包装文本的方法?
谢谢.
我安装了以下内容:
我想用自定义CSS创建一个闪亮的演示文稿(RStudio菜单项:文件>新文件> RMarkdow>闪亮>闪亮的演示文稿),但我不确定如何这样做.
我的自定义CSS(目前只更改标题2的颜色)
h2 {
font-size:1.8em;
color: red;
}
Run Code Online (Sandbox Code Playgroud)
使用ioslides网页上的RMarkdown PResentations提供的示例摘录:
---
title: "Habits"
author: John Doe
date: March 22, 2005
output:
ioslides_presentation:
css: temp.css
---
## Getting up
- Turn off alarm
- Get out of bed
Run Code Online (Sandbox Code Playgroud)
但是,当我通过包含runtime: Shiny在前导码中将其转换为生成Shiny输出时,自定义格式不再有效.
---
title: "Habits"
author: John Doe
date: March 22, 2005
runtime: shiny
output:
ioslides_presentation:
css: temp.css
---
## Getting up
- Turn off alarm
- Get out of bed
## …Run Code Online (Sandbox Code Playgroud) 如何在前言,确认等方面获得罗马数字,并在R Bookdown第一章的第一页重启阿拉伯语编号为1.
我想在bookdown中呈现为pdf,但是没有找到关于如何更改页面编号的任何好信息
谢谢