Search code examples
rlinuxescapingsystemcd

r system function to cd into a folder name with space


I trying to cd into this folder in my linux system from R.

/projects/Temp/Global Warming

I use the system function like this below

system("cd /projects/Temp/Global Warming; ls")

and this is not working.

If I try one level up, system("cd /projects/Temp; ls") everything works fine without any problems, but when it try to cd into the folder Global Warming the space is folder name is creating some problems. Any advise on how to fix this issue is much appreciated. Thanks.


Solution

  • This is not an R issue but more of a general command line issue. For cd you need to quote the path if it contains spaces.

    'cd "/projects/Temp/Global Warming"; ls' should work.