简体   繁体   English

R System2在Windows上调用R脚本时遇到麻烦

[英]R system2 trouble invoking R script on windows

I frequently use RODBC to connect with Microsoft Access databases and can only do this in 32-bit R because 32 bit MS Office is loaded on my Windows 7 PC. 我经常使用RODBC连接Microsoft Access数据库,并且只能在32位R中执行此操作,因为Windows 7 PC上已加载32位MS Office。

After extracting my data from an MS access database in 32-bit R, I usually then want to manipulate and analyse it in 64-bit R. In addition I am trying to write a script that others may need to use and I would like to simplify things by invoking 32-bit R inside RStudio (which I have set up to use 64-bit R, version 3.1.2). 从32位R的MS Access数据库中提取数据后,通常我想在64位R中进行操作和分析。此外,我试图编写一个脚本,其他人可能需要使用该脚本,我想通过在RStudio中调用32位R(我已设置为使用64位R,版本3.1.2)来简化操作。

I found this post which seemed to be just what I was looking for and attempted to run the suggested code. 我发现这篇文章似乎正是我在寻找的内容,并尝试运行建议的代码。 However, this gives me a fatal error indicating that my working directory does not exist, even though I have been working from this directory within 64 bit R and 32 bit R with and without RStudio and have never had any problems: 但是,这给了我一个致命的错误,表明我的工作目录不存在,即使我在有和没有RStudio的情况下都使用64位R和32位R中的该目录进行工作,也从未遇到过任何问题:

> system2("C:\\Users\\Joe.Bloggs\\Documents\\R\\R-3.1.2\\bin\\i386\\Rscript.exe", normalizePath("my script.R", winslash = "\\", mustWork = TRUE), invisible=FALSE)
Fatal error: cannot open file 'H:\03.': No such file or directory

Warning message:
running command '"C:\Users\Joe.Bloggs\Documents\R\R-3.1.2\bin\i386\Rscript.exe" H:\03. B Project\my script.R' had status 2

Note that I have installed R and RStudio in the "Documents" folder in the C drive since I don't have administrative rights. 请注意,由于我没有管理权限,因此我已将R和RStudio安装在C驱动器的“文档”文件夹中。

Also, my R script is on a network drive (H). 另外,我的R脚本在网络驱动器(H)上。

I have tried copying the R script I want to run to the default working directory of 32-bit R on my C drive and explicitly stating the filepath to it without using normalizePath (as I assume this command expands to my current working directory in 64-bit R), but this gives the same error as above. 我尝试将要运行的R脚本复制到C驱动器上默认的32位R工作目录,并在不使用normalizePath的情况下明确指出其路径(因为我假设此命令将扩展到64-位R),但这会产生与上述相同的错误。

Further, if I just try to invoke 32-bit R, I get a warning: 此外,如果我只是尝试调用32位R,则会收到警告:

> system2("C:\\Users\\Joe.Bloggs\\Documents\\R\\R-3.1.2\\bin\\i386\\Rscript.exe", invisible=FALSE)
Usage: /path/to/Rscript [--options] [-e expr [-e expr2 ...] | file] [args]

--options accepted are
  --help              Print usage and exit
  --version           Print version and exit
  --verbose           Print information on progress
  --default-packages=list
                      Where 'list' is a comma-separated set
                        of package names, or 'NULL'
or options to R, in addition to --slave --no-restore, such as
  --save              Do save workspace at the end of the session
  --no-environ        Don't read the site and user environment files
  --no-site-file      Don't read the site-wide Rprofile
  --no-init-file      Don't read the user R profile
  --restore           Do restore previously saved objects at startup
  --vanilla           Combine --no-save, --no-restore, --no-site-file
                        --no-init-file and --no-environ

'file' may contain spaces but not shell metacharacters
Expressions (one or more '-e <expr>') may be used *instead* of 'file'
See also  ?Rscript  from within R
Warning message:
running command '"C:\Users\Joe.Bloggs\Documents\R\R-3.1.2\bin\i386\Rscript.exe"' had status 1 

Any insights into what I am doing wrong would be much appreciated; 任何对我做错事的见解将不胜感激; I tried using single forward slashes instead of double back slashes in both file paths but to no avail; 我尝试在两个文件路径中使用单斜杠而不是双斜杠,但无济于事。 I still got the same error. 我仍然遇到相同的错误。

How can I get system2 to locate my R script and run it in 32-bit R? 如何获得system2来定位我的R脚本并在32位R中运行它?

Also is there a resource that explains what the status numbers in the warnings mean? 还有没有资源可以解释警告中的状态编号是什么意思?

Many thanks for your help. 非常感谢您的帮助。

I've been trying to do the same thing (call 32 bit R from 64bit RStudio for RODBC) and asked a similar question here . 我一直在尝试做同样的事情(从用于RODBC的64位RStudio调用32位R),并在这里提出了类似的问题。 I used a slightly different approach and did: 我使用了一种略有不同的方法并做到了:

system(paste0(Sys.getenv("R_HOME"), "/bin/i386/RScript.exe H:\\path\\to\\file.R"), wait = FALSE, invisible = FALSE)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM