我sql在.Rmd文档中使用了以下代码。但是,我想在.Rnw文档中使用相同的 SQL 代码。
```{r label = setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, max.print = NA)
```
```{r, echo=FALSE, results='hide'}
library(DBI)
db <- dbConnect(RSQLite::SQLite(), dbname = "survey.db")
dbListTables(db)
```
```{sql, label = Q1, connection=db, tab.cap = "Table Caption"}
SELECT *
FROM Person;
```
Run Code Online (Sandbox Code Playgroud)
更愿意获得代码格式和输出打印功能。
我有一个小的Rnw文件.使用knitr编译时,它会在pdf中显示导入注释.如何删除这些评论?这是文件a.Rnw:
\documentclass[10pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\begin{document}
Hi, this is an example!
<<setup, echo=FALSE, cache=TRUE>>==
library(earth, warn.conflicts=FALSE)
a <- rnorm(100); b<- 0.05*rnorm(100) - .2*a
model <- lm(a~b)
plot(model)
@
\end{document}
Run Code Online (Sandbox Code Playgroud)
当我用knitr编译时
$ Rscript -e "library(knitr); knit('a.Rnw')"
Run Code Online (Sandbox Code Playgroud)
我在tex文件中得到了这个无关的位:
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
{\ttfamily\noindent\itshape\color{messagecolor}{\#\# Loading required package: plotmo\\\#\# Loading required package: plotrix}}\end{kframe}
Run Code Online (Sandbox Code Playgroud)
显示为

这是正常的吗?如何删除这些评论?
当我使用knitr::kableRNW文件中的函数创建表格时,PDF中表格项的文本颜色看起来是灰色的。
我想将其更改为黑色。我怎样才能做到这一点?
我想xtable在candisc::cancor输出上使用函数.但是想不出来.在这方面的任何帮助将受到高度赞赏.谢谢
library(xtable)
library(candisc)
data(Rohwer, package="heplots")
X <- as.matrix(Rohwer[,6:10]) # the PA tests
Y <- as.matrix(Rohwer[,3:5]) # the aptitude/ability variables
(cc <- cancor(X, Y, set.names=c("PA", "Ability")))
Canonical correlation analysis of:
5 PA variables: n, s, ns, na, ss
with 3 Ability variables: SAT, PPVT, Raven
CanR CanRSQ Eigen percent cum scree
1 0.6703 0.44934 0.81599 77.30 77.30 ******************************
2 0.3837 0.14719 0.17260 16.35 93.65 ******
3 0.2506 0.06282 0.06704 6.35 100.00 **
Test of H0: The canonical …Run Code Online (Sandbox Code Playgroud) 我下载了新版本的 knitr 包,当尝试在 Rnw 文件中包含绘图时突然出现以下错误:
Error in options[[sprintf("fig.%s", i)]] * options$dpi :
non-numeric argument to binary operator
Calls: knit ... process_group.block -> call_block -> fix_options -> %n%
Run Code Online (Sandbox Code Playgroud)
经过大量实验后,我发现问题出在命令 Fig.height 上,显然它应该是数字。此代码产生错误:
\documentclass{article}
\begin{document}
<<cat, fig.cap="dog", fig.height='\\textheight'>>=
plot(c(1, 2, 3), c(2, 1, 3))
@
\end{document}
Run Code Online (Sandbox Code Playgroud)
这段代码没有:
\documentclass{article}
\begin{document}
<<cat, fig.cap="dog", fig.height=6>>=
plot(c(1, 2, 3), c(2, 1, 3))
@
\end{document}
Run Code Online (Sandbox Code Playgroud)
不幸的是我不知道这个 6 的测量单位是什么。
这段代码:
\documentclass{article}
\begin{document}
<<cat, fig.cap="dog", fig.height=6cm>>=
plot(c(1, 2, 3), c(2, 1, 3))
@
\end{document}
Run Code Online (Sandbox Code Playgroud)
产生不同的错误:
Error in base::parse(text = code, …Run Code Online (Sandbox Code Playgroud)