Amy M
Amy M

Reputation: 1095

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.

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).

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:

> 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.

Also, my R script is on a network drive (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.

Further, if I just try to invoke 32-bit R, I get a warning:

> 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?

Also is there a resource that explains what the status numbers in the warnings mean?

Many thanks for your help.

Upvotes: 1

Views: 2075

Answers (1)

r.bot
r.bot

Reputation: 5424

I've been trying to do the same thing (call 32 bit R from 64bit RStudio for RODBC) and asked a similar question here. 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)

Upvotes: 1

Related Questions