私はあなたが欠けているものを正確に理解していないと思いますが、ここに私が作った最小限の例があります. これを実行するには
library(knitr)
knit("r-report.html")
そしてその例。
<HTML>
<HEAD>
<TITLE>Analyzing Diamonds!</TITLE>
</HEAD>
<BODY>
<H1>Diamonds are everywhere!</H1>
<!--begin.rcode echo=FALSE
## Load libraries, but do not show this
library(ggplot2)
library(plyr)
testData <- rnorm(1)
end.rcode-->
This is an analysis of diamonds, load the data.<p>
<!--begin.rcode echo=TRUE, fig.keep="all"
# Load the data
data(diamonds)
# Preview
head(diamonds)
end.rcode-->
Generate a figure, don't show code <p>
<!--begin.rcode echo=FALSE, fig.align="center", dev="png"
# This code is not shown, but figure will output
qplot(diamonds$color, fill=diamonds$color) +
opts(title="A plot title")
end.rcode-->
Show some code, don't output the figure<p>
<!--begin.rcode echo=TRUE, fig.keep="none"
# Show the code for this one, but don't write out the figure
ggplot(diamonds, aes(carat, price, colour=cut)) +
geom_point(aes(alpha=0.9))
end.rcode-->
And the value testData: <!--rinline testData --> inside a text block.
</BODY>
</HTML>