感谢@rcs 和@hadley 的评论。
实际上,两种提议的解决方案似乎都不适合我的需求。以 Rd 格式嵌入图像并非如此,因为我使用过渡 Roxygen>Rd。'helpr' 包确实令人印象深刻,但我认为它更适合构建您计算机中安装的所有包的知识库。作为包开发人员,我需要一些更基本的东西,并且可以灵活地自己进行更改。
最后,我得到了我所期望的fitSpline.html。这与我在问题中提出的参考页面prcomp.html非常相似。
我发现没有办法采用包“工具”来在 HTML 文档中包含图像,至少现在是这样。因此,我编写了一个 bash 脚本,它在输入中获取一个 Rd 文件,提取部分 '\examples' 并通过运行 Sweave 获取 html/图像输出。之后,“结果”部分的 html 部分与通过命令“R CMD Rdconv -t html”获得的 html 页面合并。
这似乎是很多代码,但我只想与那些也编写 R 包的人分享我的解决方案。
最好的问候,安德烈
#!/bin/bash
rdfile="fitSpline.Rd"
rdname=$(echo "$rdfile" | cut -d'.' -f1)
rfile=$rdname.R
sed -n '/\examples{/,/}/p' $rdfile > $rfile # text between two patterns
sed -i 's/\\examples{//' $rfile # remove pattern '\examples{'
sed -i 's/}$//' $rfile # remove the character '}'
rnwfile=$rdname.Rnw
cp $rfile $rnwfile
sed -i '1 i png("Rplot%03d.png")' $rnwfile
sed -i '1 i <<example, echo=true, results=tex>>=' $rnwfile
sed -i '$ a dev.off()' $rnwfile
sed -i '$ a @' $rnwfile
texfile=$rdname.tex
R CMD Sweave $rnwfile
sed -i 's/\\begin{Schunk}//' $texfile
sed -i 's/\\begin{Sinput}//' $texfile
sed -i 's/\\end{Schunk}//' $texfile
sed -i 's/\\end{Sinput}//' $texfile
sed -i '/^$/d' $texfile # remove empty lines
reshtmlfile=$rdname.results.html
echo "<h3>Results</h3>" > $reshtmlfile
echo "<pre>" >> $reshtmlfile
cat $texfile >> $reshtmlfile
echo "</pre>" >> $reshtmlfile
for fig in $(ls *.png) ; do
echo "<br><a href=\"$fig\"><img src=\"$fig\"></a>" >> $reshtmlfile
done
htmlfile=$rdname.html
R CMD Rdconv -t html $rdfile > $htmlfile
sed -i 's/<\/body>//' $htmlfile
sed -i 's/<\/html>//' $htmlfile
cat $reshtmlfile >> $htmlfile
echo "</body>" >> $htmlfile
echo "</html>" >> $htmlfile