我正在延长我之前提出的两个问题:
将数字直接放入Knitr文件(不保存文件夹中的文件)第2部分
我正在编写一个R包,为输出数据汇总的用户生成.pdf文件。 我在包里有一个.Rnw脚本(在这里,我的MWE叫做test.Rnw)。 用户可以这样做:
knit2pdf("test.Rnw",clean=T)
这使得这个过程变得很容易,因为它会自动从.tex文件创build.pdf文件,并为它们擦除不必要的文件(例如.aux和.log)。 它还将任何图像存储到一个临时目录(使用tempdir()),然后将它们合并到.tex和.pdf文件之后,系统会将其常规擦除。 这意味着他们不必删除图像文件。
以下是我的testing.RWE MWE:
如何在terminal中recursion地在Ubuntu中批量调整图像大小?
体积图像数据的分布式处理
在Windows C ++中从JPG / PNG文件创build一个BITMAPINFO
dynamic加载的图像绘制到JavaScript的canvas有不正确的(但接近)的RGB值
documentclass[nohyper]{tufte-handout} usepackage{tabularx} usepackage{longtable} setcaptionfont{% changes caption font characteristics normalfontfootnotesize color{black}% <-- set color here } begin{document} <<setup,echo=FALSE>>= library(knitr) library(xtable) library(ggplot2) # Specify directory for figure output in a temporary directory temppath <- tempdir() opts_chunk$set(fig.path = temppath) @ <<diamondData,echo=FALSE,fig.env = "marginfigure",out.width="0.95\linewidth",fig.cap = "The diamond dataset has varibles depth and price.",fig.lp="mar:">>= print(qplot(depth,price,data=diamonds)) @ <<echo=FALSE,results='asis'>>= myDF <- data.frame(a = rnorm(1:10),b = letters[1:10]) print(xtable(myDF,caption= 'This data frame shows ten random variables from the distribution and a corresponding letter',label='tab:dataFrame'),floating = FALSE,tabular.environment = "longtable",include.rownames=FALSE) @ figure ref{mar:diamondData} shows the diamonds data set,with the variables price and depth.Table ref{tab:dataFrame} shows letters a through j corresponding to a random variable from a normal distribution. end{document}
我应该注意到,实际上,在我的软件包中有另一个.Rnw文件,通过调用test.Rnw文件:
knit2pdf("/inst/Rnw/test.Rnw","/path/test.tex",clean=T)
无论如何,我正试图让这个包准备好提交给CRAN,并且遇到了两个问题:
1)更复杂的问题首先:上面的MWE代码似乎在Mac系统上工作,但似乎不适用于Windows系统! 在Windows上,生成的.pdf文件不包含图像。 排除故障后,我想我已经find了问题,但仍然找不到解决scheme。
基本上,在Windows上,似乎tempdir()命令将创build一个双反斜杠的path,如\ this \是\ myPath。 然后,在.tex文件中,临时目录(包含映像)的path是单个反斜杠,例如 this is myPath。 但是,这些应该是单个正斜杠,例如/ this / is / myPath,以便.tex文件查找存储在临时目录中的映像。
事实上,如果手动将反斜杠更改为在Windows中.tex文件中正斜杠,则可以将其成功转换为成功包含图像的.pdf文件。
然而,我不确定如何在我的语法中解决这个问题。 我认为这将是一个简单的解决scheme,但如果我只是做一些事情:
# Specify directory for figure output in a temporary directory temppath <- tempdir() gsub("\\","/",temppath)
然后,即使.tex文件将包含正确的单个正斜杠,图像也不能存储在Windows上的临时目录中。 (我相信)相同的variables是用来表示临时目录位置,以及在.tex文件中的图像位置,他们不知何故必须有不同的斜线方向。
我感到有些惊讶,至less在我的研究中还没有提出。 运行knitr时,人们可能没有自动的图像擦除?
2)我想知道在我的其他.Rnw文件中添加第二行来调用是否可以接受:
knit2pdf("/inst/Rnw/test.Rnw",clean=T) system(sprintf("%s",paste0("rm -r ","/path/myFile.tex")))
这样.tex文件也可以被自动删除。 我试图确认这样的语法可以被CRAN标准接受,因为它包括从用户的计算机上删除一个文件(这看起来像是危险的/恶意软件),尽pipe它特别指出了它刚生成的.tex文件,所以它不应该删除任何重要的东西。
*注意:我默认删除所有的中间文件,所以用户只处理.pdf文件。 不过,我仍然允许用户select违反这个默认值,并保留这些中间文件,如果需要的话。
我可以使用imageMagick从图像中获取IPTC和EXIF数据吗?
C ++读取和编辑位图图像的像素
Python 3.3:如果游戏文件夹不在C驱动器中,则无法使用Pygame加载图像
最适合约250,000个图像的网页文件夹结构
当LAMP服务器上有数百万用户时,什么是最快和最有效的存储和提取图像的方式?
你提供的代码给了我一个sweave特定表达式的警告: SweaveOpts{concordance=TRUE}如果我删除这个,页面为我编译(带有大量的盒子错误),并产生PDF格式的图形在Windows(和Ubuntu )。
我也不清楚你为什么要指定你自己的临时目录:不是为你打理这件事吗?
我刚刚安装了MikTex并进行了更新(许多软件包在安装后立即是4或5年)。
我试着用R-devel和R-3.2.2:
> sessionInfo() R version 3.2.2 (2015-08-14) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64 (build 7601) Service Pack 1 locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C LC_TIME=English_United States.1252 attached base packages: [1] stats graphics Grdevices utils datasets methods base other attached packages: [1] ggplot2_1.0.1 xtable_1.7-4 knitr_1.11 loaded via a namespace (and not attached): [1] Rcpp_0.12.0 digest_0.6.8 MASS_7.3-44 grid_3.2.2 plyr_1.8.3 gtable_0.1.2 formatR_1.2 [8] magrittr_1.5 evaluate_0.7.2 scales_0.3.0 stringi_0.5-5 reshape2_1.4.1 labeling_0.3 proto_0.3-10 [15] tools_3.2.2 stringr_1.0.0 munsell_0.4.2 colorspace_1.2-6 sessionInfo() R Under development (unstable) (2015-09-27 r69432) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64 (build 7601) Service Pack 1 locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C LC_TIME=English_United States.1252 attached base packages: [1] stats graphics Grdevices utils datasets methods base other attached packages: [1] ggplot2_1.0.1 xtable_1.7-4 knitr_1.11 loaded via a namespace (and not attached): [1] Rcpp_0.12.0 digest_0.6.8 MASS_7.3-44 grid_3.3.0 plyr_1.8.3 gtable_0.1.2 formatR_1.2 [8] magrittr_1.5 evaluate_0.7.2 scales_0.3.0 stringi_0.5-5 reshape2_1.4.1 labeling_0.3 proto_0.3-10 [15] tools_3.3.0 stringr_1.0.0 munsell_0.4.2 colorspace_1.2-6
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。