感謝@ rcs和@hadley的評論。
實際上,兩種提議的解決方案似乎都不符合我的需求。以Rd格式嵌入圖像並非如此,因爲我使用了Roxygen> Rd轉換。這個軟件包的'幫助者'確實給人印象深刻,但我認爲它更適合構建您計算機中安裝的所有軟件包的知識庫。我需要一些更具基本靈活性的東西來作爲一名軟件包開發人員自己完成更改。
最後,我得到了我的預期,fitSpline.html。這與我在問題prcomp.html中提到的參考頁非常相似。
我發現在HTML文檔中至少現在沒有辦法採用包'工具'來獲取圖像。因此,我編寫了一個bash腳本,它在輸入文件上創建一個Rd文件,提取'\ examples'部分並通過運行Sweave獲取html/image輸出。之後,「結果」部分的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
請參閱:[在Rd文檔中嵌入圖像](http://romainfrancois.blog.free.fr/index.php?post/2010/04/03/embed-images-in-Rd-documents) – rcs 2011-01-20 08:18:46