Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
827 views
in Technique[技术] by (71.8m points)

r - Rscript file path with space

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 get the error:

Fatal error: cannot open file 'C:/Documents/Folder': No such file or directory

However when I use quotation marks (tried single double and triple as was suggested in other posts) I get the following error:

Rscript "C:/Documents/Folder name containing space/myscript.txt"
The filename, directory name, or volume label syntax is incorrect.

I can't find a way to get around the space problem and changing the file location so there are no white-spaces is not an option for me.

Any help would be greatly appreciated.

Further Clarifications:

The issue I am having is not directly related to R but rather to to having the file path that contains spaced being passed to Rscript.

In the documentations, Rsript should be used in the following way:

Rscript [options] [-e expr [-e expr2 ...] | file] [args]

It is also noted that:

Spaces are allowed in expression and file (but will need to be protected from the shell in use, if any, for example by enclosing the argument in quotes).

However trying to enclose the file path in quotes results in the error

The filename, directory name, or volume label syntax is incorrect.

To avoid confusion, running Rscript C:/Documents/Folder_name/myscript.txt works fine when the path doesn't contain any spaces as does Rscript "C:/Documents/Folder_name/myscript.txt".

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:DocumentsFolder-name-no-spacemyscript.txt
source("C:/Documents/Folder name containing space/myscript.txt")

Then you run it with:

Rscript C:DocumentsFolder-name-no-spacemyscript.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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...