带空间的Rscript文件路径 [英] Rscript file path with space
问题描述
我试图在Windows Shell中运行以下R脚本:
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.
任何帮助将不胜感激。
>进一步说明:
我遇到的问题与R不直接相关,而是与包含空格的文件路径传递给Rscript有关。
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.
在文档中,应按以下方式使用Rsript:
In the documentations, Rsript should be used in the following way:
Rscript [options] [-e expr [-e expr2 ...] | file] [args]
还应注意:
表达式和文件中都允许使用空格(但是,如果有使用的外壳,则需要保护它们,例如通过将引号括在引号中)。
但是尝试将文件路径括在引号中会导致错误
However trying to enclose the file path in quotes results in the error
The filename, directory name, or volume label syntax is incorrect.
为避免混乱,运行 Rscript C: /Documents/Folder_name/myscript.txt
在路径不包含任何空格时也可以正常工作, Rscript C:/Documents/Folder_name/myscript.txt
。
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"
.
推荐答案
它是R版本3.5.0(适用于Windows)中的BUG。
除了降级之外,一种解决方法是创建一个R脚本,该脚本的路径中没有空格,并使用 source()
:
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
或:
Rscript C:/Documents/Folder-name-no-space/myscript.txt
您也可以尝试使用8.3文件名。您可以通过以下方式获得它:
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
自3.5.1起,此问题已修复。
UPDATE
Since 3.5.1 the problem has been fixed.
这篇关于带空间的Rscript文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!