[英]R - run system call with space in path on Mac
I am trying to invoke some system commands on R using system()
calls. 我正在尝试使用system()
调用在R上调用一些系统命令。 However, I am having the infamous problem with spaces in the directories. 但是,我在目录中遇到了臭名昭著的问题。
For example, I am trying to use this directory: 例如,我正在尝试使用以下目录:
odir <- '/Volumes/Macintosh HD 2/data/cmip5/historical/clt/models'
on this command: 在此命令上:
system(paste('ls ', odir,sep=''))
and I receive the following error: 并且收到以下错误:
> system(paste('ls ', odir,sep=''))
ls: /Volumes/Macintosh: No such file or directory
ls: 2/data/cmip5/historical/clt/models: No such file or directory
ls: HD: No such file or directory
How can I overcome this? 我该如何克服?
Thanks! 谢谢!
Most command lines require that you escape spaces with a backslash. 大多数命令行要求您使用反斜杠转义空格。 And when you make R strings, you need to escape backslashes with a backslash. 而当您制作R弦时,您需要使用反斜杠来转义反斜杠。 Try 尝试
odir <- '/Volumes/Macintosh\\ HD\\ 2/data/cmip5/historical/clt/models'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.