Home > Blockchain >  Trying to create a directory with two lines with file.path function due to being long but getting an
Trying to create a directory with two lines with file.path function due to being long but getting an

Time:10-02

directory<-file.path(r"(C:\File\Folder1\Folder2)",
                 r"(Source\)")

I was told told that this script should work but what happens is that the outcome looks like this

C:\\File\\Folder1\\Folder2\\/Source\\

I don't understand why am i getting that forward slash right before the last folder in the output.

C:\\File\\Folder1\\Folder2\\Source\\

CodePudding user response:

There is only a single character

nchar(r"(\)")
[1] 1

The other character escape can be checked with cat

> cat(r"(\)")
\

> cat(directory)
C:\File\Folder1\Folder2/Source\

The fsep can be changed in file.path

directory <- file.path(r"(C:\File\Folder1\Folder2)",
                  r"(Source)", fsep = "\\")
> cat(directory)
C:\File\Folder1\Folder2\Source
  • Related