Windows 批处理 R Sweave 加载包时出错
我无法找到有关如何在 Windows XP 上为 Sweave 文档设置批处理文件的明确文档。
我正在使用此处找到的批处理文件
我创建了一个批处理文件名 run.bat
包含以下内容:
Sweave myFile.Rnw
设置 wd 后,我在 Sweave 文件中做的第一件事是使用 RODBC
包在数据集中读取:
library(RODBC)
fetch <- odbcConnect("myDatabase")
myData <- "select * from myTable"
x <- sqlQuery(fetch, myData)
odbcCloseAll()
当我运行时在我的批处理文件中,我收到以下错误:
Error: chunk 2
Error in library(RODBC) : there is no package called RODBC
In addition: Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called 'xtable'
显然这些包确实存在并且可以正常运行,但是权限有些问题或者找不到正确的目录。有什么想法吗?
相关问题此处
I am having trouble finding clear documentation on how to set up a batch file for a Sweave document on Windows XP.
I am using the batch files that are found here
I have created a batch file names run.bat
which contains the following:
Sweave myFile.Rnw
The first thing I do in my Sweave file after setting the wd is read in a dataset using the RODBC
package:
library(RODBC)
fetch <- odbcConnect("myDatabase")
myData <- "select * from myTable"
x <- sqlQuery(fetch, myData)
odbcCloseAll()
When I run my batch file, I receive the following error:
Error: chunk 2
Error in library(RODBC) : there is no package called RODBC
In addition: Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called 'xtable'
Obviously these packages do exist and are functional, but something isn't right in the permissions or it isn't finding the right directories. Any thoughts?
Related question here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您在 R(在 GUI 中)中键入它时,会返回什么?
当你在 Rnw 文件中运行时它显示什么?
help(Startup)
中的文档将提供一些关于在何处设置 R_LIBS 及其变体的建议。What does this return when you type it in R (in the GUI) ?
What does it show when you run in the Rnw file?
The documentation in
help(Startup)
will have several suggestions as to where you can set R_LIBS and its variants.我找到了解决问题的直接方法,尽管我知道这种方法有一定的局限性。我放弃使用 CRAN 提供的 .bat 文件来动态查找 R 的适当路径,并将 R 的路径硬编码为如下:
此
.bat
文件将启动 R,运行脚本run。 r
包含两个命令:然后清除 LaTeX 输出中的中间
.log
和.aux
文件。显然,大部分工作是在myFile.Rnw
中完成的,但这至少可以让我单击一个按钮,执行分析并生成 PDF 文件。如果有人能想出一种方法来提高效率,我将不胜感激。
I found an immediate solution to my problem, though understand there are certain limitations to this method. I abandoned using the CRAN provided .bat files for dynamically finding the appropriate path to R and hardcoded the path to R as such:
This
.bat
file will fire up R, run the scriptrun.r
which contains two commands:and then cleans up the intermediate
.log
and.aux
files from the LaTeX output. Obviously, the bulk of the work is done inmyFile.Rnw
but this will atleast let me click one button, perform my analysis, and generate the PDF file.If someone can think of a way to make this more efficient, I'd appreciate it.