Rscript file path with space

后端 未结 4 1196
情话喂你
情话喂你 2020-12-21 00:46

I am trying to run the following R script in windows shell:

Rscript C:/Documents/Folder name containing space/myscript.txt

In this case I g

相关标签:
4条回答
  • 2020-12-21 01:01

    It is a BUG in R version 3.5.0 for Windows.
    One workaround, apart from downgrading, is creating an R script with no spaces in its path and run the spaced one with source():

    ## C:\Documents\Folder-name-no-space\myscript.txt
    source("C:/Documents/Folder name containing space/myscript.txt")
    

    Then you run it with:

    Rscript C:\Documents\Folder-name-no-space\myscript.txt
    

    or also:

    Rscript C:/Documents/Folder-name-no-space/myscript.txt
    

    You may also try the 8.3 filename. You can get it with:

    for %I in ("C:/Documents/Folder name containing space/myscript.txt") do @echo %~sI
    

    UPDATE

    Since 3.5.1 the problem has been fixed.

    0 讨论(0)
  • 2020-12-21 01:10

    Simple solution: install a newer version of R.

    From the version 3.5.1 release notes, the relevant bug fix is described here:

    Allow file argument of Rscript to include space even when it is first on the command line.

    0 讨论(0)
  • 2020-12-21 01:19

    Another convenient workaround was to create an alias for the portion of the path which contains spaces, i.e.:

    SUBST k: "c:\Folder with Spaces"
    rscript k:\scripts\program.R
    
    0 讨论(0)
  • 2020-12-21 01:22

    Forward slashes work just fine with R, so don't worry about backward slashes. I've just verified and the following works at the CMD.exe terminal of Windows 8.1:

    C:\Windows\System32> Rscript "C:/Users/hb/folder with spaces/script.R"
    [1] "1+2+3"
    
    C:\Windows\System32>
    

    My best guess is that you've got the pathname incorrect. If it's a non-existing pathname, you do get:

    C:\Windows\System32> Rscript --vanilla "C:/Users/hb/folder with spaces/non-existing.R"
    Fatal error: cannot open file 'C:/Users/hb/folder with spaces/non-existing.R': No such file or directory
    

    You can validate it from within R, e.g.

    > file.exists("C:/Users/hb/folder with spaces/script.R")
    [1] TRUE
    
    0 讨论(0)
提交回复
热议问题