11

When I call Rscript.exe for Version 3.5 of R, it is unable to open the file if the file name or path has a space in it. I saved 2 files with the code:

cat("What do you get when you multiply 6 * 9?")

as C:\foo bar.R and as C:\foo_bar.R

When I in a DOS command window try to run these using version 3.4.3 and 3.5:

C:\>"C:\Program Files\R\R-3.4.3\bin\x64\Rscript.exe" "C:\foo bar.R"
What do you get when you multiply 6 * 9?
C:\>"C:\Program Files\R\R-3.4.3\bin\x64\Rscript.exe" "C:\foo_bar.R"
What do you get when you multiply 6 * 9?
C:\>"C:\Program Files\R\R-3.5.0\bin\x64\Rscript.exe" "C:\foo bar.R"
Fatal error: cannot open file 'C:\foo': No such file or directory


C:\>"C:\Program Files\R\R-3.5.0\bin\x64\Rscript.exe" "C:\foo_bar.R"
What do you get when you multiply 6 * 9?
C:\>

When I try to run the file with a space in the name in version 3.5.0 of R, there is a fatal error saying there is no such file.

Kerry Jackson
  • 1,821
  • 12
  • 20
  • 1
    I get the same behavior, and I'd agree that this is a bug. Unfortunately, problems with the R Core are not that easy to report. An e-mail to `r-devel@r-project.org` seems to be the only option according to the info on this page: https://www.r-project.org/bugs.html – Edward Carney Apr 25 '18 at 18:16
  • 2
    But in general I think it's bad practice to have spaces in filename – Tung Apr 25 '18 at 21:14

1 Answers1

6

Thanks Edward Carney, I emailed the address you listed, and got a response from Tomas confirming it is a bug, and providing a workaround until it is fixed:

A quick workaround before this gets fixed is to add an extra first argument that has no space in it, e.g.

Rscript --vanilla "foo bar.R"

The problem exists on all systems, not just Windows.

This has now been corrected in the Development version, and there is a binary build for Windows at: https://cran.r-project.org/bin/windows/base/rdevel.html

It has also been corrected in the patched version, and there is a binary build for Windows at: https://cran.r-project.org/bin/windows/base/rpatched.html

Kerry Jackson
  • 1,821
  • 12
  • 20
  • I'd use `--slave` instead of `--vanilla`. The latter means no `.Rprofile`/`.Renviron` will be respected. Thanks for reporting the bug to R core! https://stat.ethz.ch/pipermail/r-devel/2018-April/075869.html – Yihui Xie Apr 28 '18 at 17:35