Windows 批处理 R Sweave 加载包时出错

发布于 2024-09-16 10:10:39 字数 975 浏览 7 评论 0原文

我无法找到有关如何在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

有深☉意 2024-09-23 10:10:39

当您在 R(在 GUI 中)中键入它时,会返回什么?

 .libPaths()

当你在 Rnw 文件中运行时它显示什么?

help(Startup) 中的文档将提供一些关于在何处设置 R_LIBS 及其变体的建议。

What does this return when you type it in R (in the GUI) ?

 .libPaths()

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.

绝不放开 2024-09-23 10:10:39

我找到了解决问题的直接方法,尽管我知道这种方法有一定的局限性。我放弃使用 CRAN 提供的 .bat 文件来动态查找 R 的适当路径,并将 R 的路径硬编码为如下:

"C:\Program Files\R\R-2.11.0\bin\Rterm.exe" --vanilla <%run.r>%run.r
 del *.log
 del *.aux

.bat 文件将启动 R,运行脚本 run。 r 包含两个命令:

Sweave("myFile.Rnw")
tools::texi2dvi("myFile.tex", pdf=TRUE)

然后清除 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:

"C:\Program Files\R\R-2.11.0\bin\Rterm.exe" --vanilla <%run.r>%run.r
 del *.log
 del *.aux

This .bat file will fire up R, run the script run.r which contains two commands:

Sweave("myFile.Rnw")
tools::texi2dvi("myFile.tex", pdf=TRUE)

and then cleans up the intermediate .log and .aux files from the LaTeX output. Obviously, the bulk of the work is done in myFile.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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文